当前位置: 代码迷 >> Android >> android点击Button后,buttton的背景跟颜色改变
  详细解决方案

android点击Button后,buttton的背景跟颜色改变

热度:70   发布时间:2016-04-28 02:46:41.0
android点击Button后,buttton的背景和颜色改变
  <Button
                    android:background="@drawable/et_bg"
                    android:textColor="@drawable/login_btn_textcolor"

                       />

背景代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_focused="true" android:drawable="@drawable/et_bg_press" /> <!-- focused -->  
    <item android:state_pressed="true" android:drawable="@drawable/et_bg_press" /> <!-- pressed -->  
    <item android:state_selected="true" android:drawable="@drawable/et_bg_press" /> <!-- pressed -->  
    <item android:drawable="@drawable/tv_bg" /> <!-- default -->  //没有pressed时button的背景
</selector>

颜色代码

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_focused="true" android:color="@color/white" /> <!-- focused -->  
    <item android:state_pressed="true" android:color="@color/white" /> <!-- pressed -->  
    <item android:state_selected="true" android:color="@color/white" /> <!-- pressed -->  
    <item android:color="@color/title" /> <!-- default -->  //没有pressed时button的颜色


</selector>

  相关解决方案