ImageButton 选择器不起作用?

发布于 2024-08-19 18:30:31 字数 868 浏览 4 评论 0原文

我正在尝试使 ImageButton 处于按下、聚焦和正常状态。 我已经阅读了 ImageButton 的介绍 这里

我保存了选择器 XML文件位于 /res/drawable/ 中。还要设置 android:src="@drawable/my_selector"

my_selector.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_unfocus" /> <!-- default -->
    <item android:state_pressed="true"
          android:drawable="@drawable/btn_onpress" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/btn_onfocus" /> <!-- focused -->
</selector>

我认为我已经完成了正确的 ImageButton。但这对我不起作用。

这里出了什么问题?

请指教。

I am trying to make ImageButton for state of pressed, focused and normal.
I've read introduction of ImageButton here

I've saved selector XML file in /res/drawable/. Also set the android:src="@drawable/my_selector".

my_selector.xml file :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_unfocus" /> <!-- default -->
    <item android:state_pressed="true"
          android:drawable="@drawable/btn_onpress" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/btn_onfocus" /> <!-- focused -->
</selector>

I think I've done correct ImageButton. But it didn't work for me.

What is wrong here ?

Please advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃扇骨 2024-08-26 18:30:31

应订购物品标签。
所以先按下,聚焦,最后一个是默认项目

请参阅这里

Item tags should be ordered.
So pressed first, focused, and the last is default item

Refer Here

長街聽風 2024-08-26 18:30:31

你理解错了。
试试这个。

android:background="@drawable/your_selector_name"

You're getting it wrong.
Try this.

android:background="@drawable/your_selector_name"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文