xml中设置button的背景颜色

本文介绍了在Android中设置Button背景颜色的两种方法:一是通过selector XML文件结合color资源实现颜色切换,二是使用9patch图片作为背景。详细讲述了各个XML文件的配置和资源引用,展示了如何根据不同状态改变Button的背景颜色。
摘要由CSDN通过智能技术生成

在画几个设置界面,用到了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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值