android Button 按下之后文字颜色改变
androidButton按下之后文字颜色改变并且保持用什么方法比较好?用配置文件来写的话一般都是松开之后又会变回去,用代码怎么实现呢?用setOnTouchListen...
android Button 按下之后文字颜色改变并且保持用什么方法比较好?用配置文件来写的话一般都是松开之后又会变回去,用代码怎么实现呢?用setOnTouchListener()改变按钮背景颜色的同时可以设置改变文字的颜色吗?具体怎么实现?求解答,谢谢!
展开
2个回答
展开全部
添加一个selecter选择器,然后设置textColor的时候选择自定义的这个选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/activity_main_tabselected" android:state_pressed="true" android:state_checked="true"/>
<item android:color="@color/activity_main_tabselected" android:state_pressed="true" android:state_checked="false"/>
<item android:color="@color/activity_main_tabselected" android:state_pressed="false" android:state_checked="true"/>
<item android:color="@color/activity_main_tabnormal" android:state_pressed="false" android:state_checked="false"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/activity_main_tabselected" android:state_pressed="true" android:state_checked="true"/>
<item android:color="@color/activity_main_tabselected" android:state_pressed="true" android:state_checked="false"/>
<item android:color="@color/activity_main_tabselected" android:state_pressed="false" android:state_checked="true"/>
<item android:color="@color/activity_main_tabnormal" android:state_pressed="false" android:state_checked="false"/>
</selector>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询