【问题标题】:How to change the text color when the button is being pressed?按下按钮时如何更改文本颜色?
【发布时间】:2010-07-04 05:35:39
【问题描述】:

我正在实现类似于 Microsoft Zune HD 播放器的用户界面。因此,我想在按下按钮以及单击按钮时更改按钮的文本颜色。

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    案件已解决。我刚刚在我的颜色文件夹中添加了一个 XML 文件。添加一个选择器 XML 并将我的按钮的属性“textColor”更改为该选择器 XML。

    进一步参考 - Android selector & text color

    【讨论】:

      【解决方案2】:

      在 res/drawable 中,创建一个名为 mybutton_background.xml 的文件,并在其中放入如下内容:

      <?xml version="1.0" encoding="utf-8"?>
      <selector android="http://schemas.android.com/apk/res/android">
      <item android:state_focused="true" android:state_pressed="false"
      android:drawable="@drawable/button_background_focus" />
      <item android:state_focused="true" android:state_pressed="true"
      android:drawable="@drawable/button_background_pressed" />
      <item android:state_focused="false" android:state_pressed="true"
      android:drawable="@drawable/button_background_pressed" />
      <item drawable="@drawable/button_background_normal">
      </selector>
      

      然后使用android:background="@drawable/mybutton_background"将此drawable设置为按钮的背景。

      【讨论】:

      • 实际上,我正在尝试更改文本颜色而不是背景,因为无论处于何种状态,我的背景都将保持黑色。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 2019-10-13
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      相关资源
      最近更新 更多