android button按下同时改变背景和文字颜色,抬起后回复原来的样子

解决方案 »

  1.   

    两种方案:
    1.继承Button类,实现myButton子类
    2.通过TextView派生出来的给个例子:
    http://marshal.easymorse.com/archives/3059
      

  2.   

    或者自己实现一套button的style 
    我记得是有press_down和up两种style的
    你可以在你自定义的button里面载入这两种style就好了
      

  3.   

    直接用两个selector呗写两个xml文件。android:background="@drawable/button_color"
    android:textColor="@drawable/text_color"参考:http://archive.cnblogs.com/a/2218778/
      

  4.   

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">    
    <!-- 默认时的背景图片 -->     
      <item android:drawable="@drawable/mv2" />       
    <!-- 没有焦点时的背景图片 -->     
      <item android:state_window_focused="false"      
            android:drawable="@drawable/mv2" />      
    <!-- 非触摸模式下获得焦点并单击时的背景图片 -->     
      <item android:state_focused="true" android:state_pressed="true"      
            android:drawable= "@drawable/mv2" />     
    <!-- 触摸模式下单击时的背景图片 -->     
      <item android:state_focused="false" android:state_pressed="true"      
            android:drawable="@drawable/mv2" />      
    <!--选中时的图片背景  -->     
      <item android:state_selected="true"      
            android:drawable="@drawable/mv2" />      
    <!--获得焦点时的图片背景  -->     
      <item android:state_focused="true"      
            android:drawable="@drawable/mv2" />      
    </selector>
    使用selectot这个方法