在画几个设置界面,用到了button控件,对于button空间的背景色在不同状态下的颜色改变方法,做了一下尝试,发现了两种背景颜色改变的方法,就总结了下。
方法一尝试了好多遍才好,要点在于,在selector中android:drawable="@drawable/button_focus"引号中为xml文件,此xml文件为color类型,且在此color xml文件中
<color xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/button_focus_color"> <!-- 注意此处android:color的位置 -->
</color>
android:color="@color/button_focus_color"在color控件中。
方法一:填充button背景颜色的方法
在factory_reset这个xml文件中,其具体xml文件为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="560px"
android:layout_height="348px"
android:background="#212121"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" > <!-- 怎样设置 -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:text="确定要恢复出厂设置吗?"
android:textColor="#e6e6e6"
android:textSize="34px"
android:paddingTop="68px"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal" >
<Button
android:id="@+id/bn1"
android:layout_width="520px"