我正在开发安卓应用程序
我为每个按钮状态(按下、正常)设置了不同的背景drawable和文本颜色
我创建了statelistdrawable对象来添加背景drawable,但现在我的问题是如何设置文本颜色
有人可以帮忙吗?
我正在开发安卓应用程序
我为每个按钮状态(按下、正常)设置了不同的背景drawable和文本颜色
我创建了statelistdrawable对象来添加背景drawable,但现在我的问题是如何设置文本颜色
有人可以帮忙吗?
按钮是一个 TextView ,您可以在 TextView 上调用 button.setTextColor(someColorStateList)
。
以下是以编程方式执行此操作的方法:
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{R.attr.state_pressed},
new int[]{R.attr.state_selected},
new int[]{-R.attr.state_selected},
},
new int[]{
Color.GREEN,
Color.BLUE,
Color.RED});
TextView textView = ... some textView or button
textView.setTextColor(colorStateList);
你当然可以使用XML配置做同样的事情(在xml中定义你的颜色状态列表,并将其与按钮文本颜色属性android:textColor="@drawable/mycolorstatelist"
关联起来)。