适用于不同的风格按钮当pressed [英] Apply Different Style to Button When Pressed

查看:156
本文介绍了适用于不同的风格按钮当pressed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法把样式应用到一个按钮,该按钮时pssed $ P $?

Is there a way to apply a style to a button when the button is pressed?

如果我有一个风格的 style.xml

<resources>
    <style name="test">
        <item name="android:textStyle">bold</item>
    </style>
</resources>

在一个选择的 button.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/test_pressed"
              style="@style/test"
          android:state_pressed="true"/>
    <item android:drawable="@drawable/test_focused"
          android:state_focused="true"/>
    <item android:drawable="@drawable/test_normal"/>
</selector>

那么我将如何引用 button.xml 在我的布局?

<Button
        ...
        android:???="button"/>

谢谢!

推荐答案

罗曼盖伊表明,它是不可能的:

Romain Guy suggests it is not possible:

<一个href="http://$c$c.google.com/p/android/issues/detail?id=8941">http://$c$c.google.com/p/android/issues/detail?id=8941

选择仅适用于可绘,而不是文本的外观。有   目前没有计划来实现这一目标。

"Selector works only for drawables, not text appearances. There is currently not plan to make this happen."

这篇关于适用于不同的风格按钮当pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆