gpt4 book ai didi

android - 布局更改未反射(reflect)在应用程序中

转载 作者:太空狗 更新时间:2023-10-29 13:41:18 31 4
gpt4 key购买 nike

我通过引用 this 创建了一个带有自定义图像的按钮小部件文章。我已经为 onclick 和 onfocus 设置了图像。但是我只能看到按钮的正常图像,当我聚焦或按下按钮时没有任何变化。

这是我的代码:

custom_button.xml:

<?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>

即您必须将默认的 item 放在末尾。似乎 android 将其扩展为 switch-case block 。

关于android - 布局更改未反射(reflect)在应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5513746/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com