Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 为按钮定义xml文件以根据状态更改背景和textColor大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我用它来做我自己的按钮来设置按下和未按下状态的背景:

<?xml version="1.0" encoding="utf-8"?>
<item android:drawable="@drawable/btn1_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/btn1_unpressed"/> <!-- default -->

但我也喜欢textColor在状态下变成白色.
我试着在项目中添加textColor =“#ffffff”,但我猜这不是正确的方法,因为它不起作用.

如果不在每个使用此按钮的java文件中编写代码,最好的方法是什么?

谢谢!

解决方法

最好的方法是将Textcolor和BACkground资源分开设置.

android:BACkground="@drawable/BACkground"
android:textColor="@drawable/button_text_color"

所以你的背景:你自己写的

和Textcolor:

<?xml version="1.0" encoding="UTF-8"?>
<SELEctor
  xmlns:android="http://scheR_239_11845@as.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#ffffffff" />
    <item android:color="#ff000000" />
</SELEctor>

大佬总结

以上是大佬教程为你收集整理的android – 为按钮定义xml文件以根据状态更改背景和textColor全部内容,希望文章能够帮你解决android – 为按钮定义xml文件以根据状态更改背景和textColor所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。