【发布时间】:2013-08-21 14:40:30
【问题描述】:
我对按钮的自定义背景有疑问。这是我的 9 补丁:
在 Draw 9-patch 中相同:
最后,结果显示在设备的屏幕上:
这就是描述我的按钮的代码:
布局:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
style="@style/button"/>
风格:
<style name="button">
<item name="android:background">@drawable/button</item>
<item name="android:textColor">@color/button_text</item>
</style>
@drawable/button:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" >
<bitmap android:src="@drawable/button_test"/>
</item>
</selector>
res文件夹中drawable的文件名是button_test.9.png
您知道为什么它不起作用吗?谢谢。
【问题讨论】:
-
可能是编译问题。清理并重建?
-
另外,你应该把drawable直接放在item中:
<item android:state_pressed="false" android:drawable="@drawable/button_test"/>
标签: android android-view nine-patch android-styles