当前位置:首页 » 安卓系统 » androidbutton的样式

androidbutton的样式

发布时间: 2022-06-28 19:05:30

① android中button有几种状态

Android中,button按钮通常有三个状态:

1. normal(正常状态);
2. focus(焦点状态);
3. pressed(按下状态)
4. selected(选中状态)

注意:按下后未松开前是pressed,表示按下。
松开后当前项目获得焦点,是focused。
focused的项只有一个,selected是当选中该按钮时显示的状态。

② android怎么改变button中字体的格式

使用方法 第一种是在listview中配置android:listSelector=”@drawable/list_item_bg” 第二种是在listview的item中添加属性android:background=”@drawable/list_item_bg” 第三种是java代码中使用: Drawable drawable = getResources()/apk/res/android">" target="_blank">schemas/apk/res/android"></a> <item android:state_selected="true" android:color="#FF0000" /> <item android:state_focused="true" android:color="#00FF00" /> <item android:state_pressed="true" android:color="#0000FF" /> <item android:color="#000000" /></selector>使用方法 android:textColor="@drawable/button_color" 更复杂的效果 还可以实现更复杂的效果,例如渐变等等。 drawable/button_color/apk/res/android">" target="_blank">schemas/apk/res/android"></a> <item android:state_pressed="true"> <!-- 定义当button 处于pressed 状态时的形态。--> <shape> <gradient android:startColor="#8600ff" /> <stroke android:width="2dp" android:color="#000000" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:bottom="10dp" android:right="10dp"/> </shape> </item> <item android:state_focused="true"> <!-- 定义当button获得 focus时的形态 --> <shape> <gradient android:startColor="#eac100"/> <stroke android:width="2dp" android:color="#333333" color="#ffffff"/> <corners android:radius="8dp" /> <padding android:left="10dp" android:top="10dp" android:bottom="10dp" android:right="10dp"/> </shape> </item></selector>使用方法 android:background="@drawable/button_color" android:focusable="true"

③ 安卓UI自定义radiobutton样式

自定义RadioButton样式分为两步:

1、自定义好样式:

打开style.xml,添加一个item

<stylename="RadiobuttonStyle">
<itemname="android:gravity">center</item>
<itemname="android:textSize">16sp</item>
<itemname="android:textColor">@color/text_select_color</item>
<itemname="android:button">@null</item>
<itemname="android:drawableTop">@drawable/select_rbtn_home</item>
</style>

2、在RadioButon中引用:

<RadioButton
android:id="@+id/tv_tab_home"
style="@style/RadiobuttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/tab_home"/>

④ android button disable 样式问题

安卓系统从selector文件里找匹配项的时候是从上往下找的,找到第一个符合的就不再往下走了,你的第一个Item什么也没写,表示符合任务状态。你可以把你的两个item换下顺序试试。

⑤ android 怎么让button按钮样式改变

<Button style="@android:style/Widget.ImageButton"//引用系统样式 android:layout_width="wrap_content" android:layout_height="wrap_content" />

⑥ android studio中的button有哪些方法

先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下:
public
Button(Context
context,
AttributeSet
attrs)
{
this(context,
attrs,
com.android.internal.R.attr.buttonStyle);
}
1
2
3
其中com.android.internal.R.attr.buttonStyle就是我们修改样式的关键了,网上的教程的修改方法大都是:
<Button
style="@style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:text="价格"
/>
1
2
3
4
5
6
也就是在对应的xml里面button控件里面编写style达到目的。
但是如果我们的app需要完全统一整个应用的button的样式,那么就需要在每一个button里面添加style。
这显然效率太低下了。
接下来打开我们项目中values文件夹下面的styles.xml文件,我们创建安卓项目的时候,会有一个默认的styles文件。
打开之后找到这段代码:
<style
name="AppBaseTheme"
parent="Theme.Holo.Light">
<!--
Theme
customizations
available
in
newer
API
levels
can
go
in
res/values-vXX/styles.xml,
while
customizations
related
to
backward-compatibility
can
go
here.
-->
</style>
<!--
Application
theme.
-->
<style
name="AppTheme"
parent="AppBaseTheme">
1
2
3
4
5
6
7
8
9
10
不保证读者的默认styles.xml和我的是一样的,不过大概是这个样子,有可能读者的最低支持是2.3、那么就没有Them.Light。
我们使用eclipse的快捷键打开这个Theme.Holo.Light。可以看到如下代码:
<style
name="Theme.Holo.Light"
parent="Theme.Light">
<item
name="colorForeground">@android:color/bright_foreground_holo_light</item>
<item
name="colorForegroundInverse">@android:color/bright_foreground_inverse_holo_light</item>
<item
name="colorBackground">@android:color/background_holo_light</item>
<item
name="colorBackgroundCacheHint">@android:drawable/background_cache_hint_selector_holo_light</item>
<item
name="disabledAlpha">0.5</item>
<item
name="backgroundDimAmount">0.6</item>

⑦ 如何自定义android Button样式

主要有2种方式进行自定义android button 的样式。

【主要方式】

  1. 自定义button样式。

  2. 自定义style样式。


【原理】

通过android sdk提供的方案进行自定义相关的android button的样式。

【详细实现步奏】

1.自定义button样式

主要是通过自定义背景图或者通过自定义selector的方式形成button的样式效果。

1.1图片的方式:

<?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android">
<itemandroid:state_pressed="true"android:drawable="@drawable/a1";/>
<itemandroid:state_focused="true"android:drawable="@drawable/a2";/>
<itemandroid:drawable="@drawable/a1";/>
</selector>

xm布局文件使用

<Buttonandroid:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_style">
</Button>

1.2 自定义selector的方式,selector 种使用以下属性进行自定义自己所需要的按钮样式。

gradient 主体渐变,startColor开始颜色,endColor结束颜色 , angle开始渐变的角度(值只能为90的倍数,0时为左到右渐变,90时为下到上渐变,依次逆时针类推) stroke 边框 width 边框宽度,color 边框颜色, corners 圆角 radius 半径,0为直角, padding text值的相对位置。

2.自定义style样式

如下样式:

<resourcesxmlns:android="http://schemas.android.com/apk/res/android">
<stylename="AppBaseTheme"parent="android:Theme.Light">
</style>
<stylename="AppTheme"parent="AppBaseTheme">
</style>
<stylename="btnStyle">
<itemname="android:textSize">30px</item>
<itemname="android:width">15px</item>
<itemname="android:height">15px</item>
</style>
</resources>

xml文件中引用

<Button
style="@style/btnStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"/>

【最后】

2种方式组合使用效果更佳,效率更高,修改方便。

⑧ android button 样式怎么写

如何自定义android Button样式

android自带的样式比较难看,如何能够自定义按钮的样式,使其显示的跟美工设计的效果一样,现与大家分享下

工具/原料

eclipse ADT

方法/步骤

在layout中添加2个按钮,从下图中可以看出在按钮中调用了style和android:background属性,这两个属性一个是自定义样式,一个是给按钮添加背景图片,下面详细介绍下

展开res目录,可以看到在values目录下有styles.xml文件,该文件用于自定义样式,双击打开

下图中标注的是我自定义的样式,name为BtnStyle,当按钮调用自定义样式的时候访问这个name

下图是在button中调用自定义样式的方法,比较简单

下面分享下如何往按钮中添加自定义图片,使按钮看起来更漂亮些,因不同手机分辨率不同,那必然牵扯到图片的拉伸,在android系统下有个很好的技术“九宫格“,可以对图片进行处理,只对局部进行拉伸,给工具目录存储在android\sdk\tools\draw9patch.bat,经过该工具处理的图片以.9.png结尾,放到drawable文件夹中

下图是在Button中通过android:background属性加载图片的方法,至此我们自定义的按钮样式也就完成了,当然这只是个引子,在具体的项目工程中实现的效果要比这个demo复杂很多,有好的设计思路欢迎交流。

出自:http://jingyan..com/article/454316ab4bdc66f7a7c03a13.html

⑨ android studio的button在点击时,点击后样式

Button只能实现按下去的时候的变化, 但是松开手就会恢复, 如果你想按下去变化一下一直保持, 那你就要用 checkBox 这类形的开关控件, 因为它们都有一个状态 isChecked true时表示一个, false表示另外一个, 可以用 selector来实现的.

热点内容
聚会编程题 发布:2024-05-04 04:02:41 浏览:403
我的世界服务器自动扫地 发布:2024-05-04 03:48:41 浏览:611
4500能配什么电脑配置 发布:2024-05-04 03:22:29 浏览:591
阿U编程课堂 发布:2024-05-04 03:10:23 浏览:617
上传音乐搜音乐 发布:2024-05-04 03:10:23 浏览:600
编译器工作负载 发布:2024-05-04 03:06:09 浏览:421
摩斯编译 发布:2024-05-04 03:06:00 浏览:612
源码得反码 发布:2024-05-04 03:05:18 浏览:753
手机搜狐怎么上传视频 发布:2024-05-04 02:50:54 浏览:75
存储卡那里有卖 发布:2024-05-04 02:45:42 浏览:968