button改变背景与文字颜色

1、定义/zhsh/res/color/txt_guide_selector.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="@android:color/black"></item>
    <item android:color="#fff"></item>

</selector>

2、定义/zhsh/res/drawable/btn_guide_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/button_red_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/button_red_normal"></item>

</selector>

3、修改/zhsh/res/layout/activity_guide.xml中按钮的属性

<Button
        android:id="@+id/btn_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="60dp"
        android:background="@drawable/btn_guide_selector"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:text="开始体验"
        android:textColor="@color/txt_guide_selector"
        android:visibility="gone" >
    </Button>

 

posted @ 2016-11-04 08:06  ecollab  阅读(3131)  评论(0编辑  收藏  举报