Android 布局更改不会反映在应用程序中
通过参考本文,我创建了一个带有自定义图像的按钮小部件。我已经为onclick和onfocus设置了图像。但我只能看到按钮的正常图像,当我对焦或按下按钮时,没有任何变化 这是我的密码: 自定义按钮。xml:Android 布局更改不会反映在应用程序中,android,layout,button,android-layout,imagebutton,Android,Layout,Button,Android Layout,Imagebutton,通过参考本文,我创建了一个带有自定义图像的按钮小部件。我已经为onclick和onfocus设置了图像。但我只能看到按钮的正常图像,当我对焦或按下按钮时,没有任何变化 这是我的密码: 自定义按钮。xml: <?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawa
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_reload_4" />
<item
android:drawable="@drawable/ic_reload_2"
android:state_pressed="true" />
<item
android:drawable="@drawable/ic_reload_3"
android:state_focused="true" />
</selector>
<Button
android:id="@+id/reload_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_button" />
布局:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_reload_4" />
<item
android:drawable="@drawable/ic_reload_2"
android:state_pressed="true" />
<item
android:drawable="@drawable/ic_reload_3"
android:state_focused="true" />
</selector>
<Button
android:id="@+id/reload_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_button" />
图像放置在可绘制文件夹中。我不知道为什么它不起作用。我还遇到了布局方面的问题,也就是说,当选择“布局”选项卡时,我可以看到eclipse中的更改,但在更新之后,它不会显示在应用程序中。有人能帮我吗…您的选择器应该是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_reload_2"
android:state_pressed="true" />
<item
android:drawable="@drawable/ic_reload_3"
android:state_focused="true" />
<item android:drawable="@drawable/ic_reload_4" />
</selector>
也就是说,您必须将默认的
项
放在末尾。android似乎像一个开关盒
块一样将其膨胀。谢谢!!。。这是我的错误,我没有完全遵循文档:)我还注意到,在某些情况下,更改显示在eclipse(布局选项卡)中,但不显示在应用程序中。例如:我在一个布局中有3个标题。我用strings.xml中定义的颜色值设置了所有3个标题的背景。我可以在eclipse中看到更改,但在我的应用程序中,更改应用于第一个标题。你知道吗?