㈠ 如何设置android的按钮的背景颜色
设置android:background属性就行了!
你的采纳是我前进的动力,
记得好评和采纳,答题不易,互相帮助,
手机提问的朋友在客户端右上角评价点(满意)即可.
如果你认可我的回答,请及时点击(采纳为满意回答)按钮!!
㈡ android的圆角矩形按钮button如何实现按下按钮颜色会变
android 设置圆角按钮后,按下按钮后,还能改变按钮的颜色
<?xml version="1.0" encoding="UTF-8"?>
<item android:state_pressed="false">
<shape android:shape="rectangle" >
<!-- 填充的颜色 -->
<solid android:color="@color/btn_register_normal"></solid>
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="15dip" />
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/lightblue" />
<corners android:radius="15dip" />
</shape>
</item>
</selector>
2. 圆角有时候需要设置一边是圆角,一边是方形的。
<?xml version="1.0" encoding="utf-8"?>
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"/>
<!-- 这是半透明,还可以设置全透明,那就是白色边框的效果了 -->
<solid android:color="#ff065e8d" />
<stroke
android:dashGap="0dp"
android:width="4dp"
android:color="@android:color/white" />
</shape>
㈢ 如何在安卓中为按钮添加颜色
安卓中为按钮添加颜色,只需要在xml布局文件中对按钮控件设置即可。
只需要设置background属性
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
/>
㈣ android怎么改变按钮颜色
可以用代码设置替换Button的背景颜色
btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.图片的路径));
㈤ android 点击一个按钮,就同时改变周围按钮背景颜色
你可以用建立Button数组,然后遍历Button,设置每一个Button的ID,让所有Button公用一个监听器。在监听器里面获取ID,并且计算他上下左右的ID,如左边减一,右边加一,上面减6,下面加6,注意判断可能上下左右没有的情况。然后设置背景颜色即可。
㈥ 安卓界面布局如何改变所有button的背景颜色
可以使用selector来实现Button的特效
main.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
<SPAN style="COLOR: #ff0000">android:textColor="@color/button_text" </SPAN>/>
</LinearLayout>
www.2cto.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
android:textColor="@color/button_text" />
</LinearLayout>
XML 文件保存在res/color/button_text.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
背景选择器-selector
概述
在drawable/xxx.xml中配置,通过配置selector,可以使系统运行时根据控件对象的状态使用相应的图片、文字等。
selector中的常用属性
android:state_selected 控件选中状态,可以为true或false
android:state_focused 控件获得焦点状态,可以为true或false
android:state_pressed 控件点击状态,可以为true或false
android:state_enabled 控件使能状态,可以为true或false
android:state_checkable 控件可勾选状态,可以为true或false
android:state_checked 控件勾选状态,可以为true或false
注意:在状态描述中,第一个匹配当前状态的item会被使用。因此,如果第一个item没有任何状态特性的话,那么它将每次都被使用,所以默认的值必须总是在最后。
android:window_focused 应用程序窗口焦点状态,可以为true或false
android:color 定义特定状态的颜色
#rgb
#argb
#rrggbb
#aarrggbb
为16进制颜色。这个颜色由rgb值指定,可带alpha,必须以”#“开头,后面跟随alpha-red-green-blue信息,格式可以为:
使用selector设置背景
把下面的XML保存成.xml文件(比如list_item_bg.xml),运行时系统会根据ListView中列表项的状态来使用相应的背景图片。
drawable/list_item_bg.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片 -->
<item android:drawable="@drawable/pic1" />
<!-- 没有焦点时的背景图片 -->
<item android:state_window_focused="false"
android:drawable="@drawable/pic1" />
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item android:state_focused="true" android:state_pressed="true"
android:drawable= "@drawable/pic2" />
<!-- 触摸模式下单击时的背景图片 -->
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/pic3" />
<!--选中时的图片背景 -->
<item android:state_selected="true"
android:drawable="@drawable/pic4" />
<!--获得焦点时的图片背景 -->
<item android:state_focused="true"
android:drawable="@drawable/pic5" />
</selector>
使用方法
第一种是在listview中配置android:listSelector=”@drawable/list_item_bg”
第二种是在listview的item中添加属性android:background=”@drawable/list_item_bg”
第三种是java代码中使用:
Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg);
listview.setSelector(drawable);
注:列表有时候为黑的情况,需要加上下面的代码使其透明:
android:cacheColorHint="@android:color/transparent"
使用selector设置字体颜色
drawable/button_font.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<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.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<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"
㈦ android的xml中怎么实现按钮按下去变颜色
在drawable里新建一个xml,然后写
<selector>
<item android:state_pressed="true" android:drawable="按下时的样式"><item>
<item android:state_pressed="false" android:drawable="正常时的样式"><item>
<selector>
然后可以再去创建两个drawable来绘制形状
如果你只是需要改变颜色那么直接在string.xml里写这样两条也行
<drawable name="正常时的样式名字">正常时的颜色值</drawable>
<drawable name="按下时的样式名字">按下时的颜色值</drawable>
然后名字一一对应就行了
别忘了在控件里引用
android:background="你之前设置的选择器"
㈧ 怎么Android编程中设置Button的字体颜色呢
<Button
android:text="123"
android:textColor="@color/aliceblue" //设置字体颜色
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
望采纳!
㈨ android怎样设置button颜色
在Xml文件中 加 android:textColor="#FF0000"
在java文件的控件中 mButton.setTextColor(Color.RED);
你也可以自定义
㈩ Android studio升级到4.1后按钮颜色无法改变
解决办法:1.删除AndroidStudioX.X文件,一般在C盘,你自己的用户目录下。2.删除C:\Users\xxx\AppData\Roaming\Google\AndroidStudio4.1\plugins下的所有文件(要是能找到哪个插件导致启动失败可以单独删除对应的插件文件),我的是删除部分插件就可以启动的。
这样重新进入studio就可以正常启动了。