我使用样式创建了带有阴影的按钮:
<style name="test">
<item name="android:shadowColor">#FFFFFF</item>
<item name="android:shadowRadius">1</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
</style>
这会在正常状态下的按钮文本上应用白色阴影。我只是想知道是否有人知道当按钮处于按下状态时是否有办法去除这个阴影。换句话说,有没有办法在按钮处于另一种(按下)状态时应用另一种样式?
提前致谢!
编辑
bold.xml:
<resources>
<style name="bold_text">
<item name="android:textStyle">bold</item>
</style>
</resources>
按钮.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/test_pressed"
style="@style/bold_text"
android:state_pressed="true"/>
<item android:drawable="@drawable/test_focused"
android:state_focused="true"/>
<item android:drawable="@drawable/test_normal"/>
</selector>
我的布局:
<Button
...
android:background="@drawable/button"/>
最佳答案
你想要一个 ColorStateList http://developer.android.com/guide/topics/resources/color-list-resource.html
关于android - 自定义按钮 : change style when pressed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3682224/