Android:通过代码更改按下/聚焦的资源

发布于 2024-09-10 12:31:59 字数 461 浏览 3 评论 0原文

我正在使用一些调整,允许用户使用他们的 SDCard 资源更改我的应用程序的 UI。这真的很简单,没什么特别的,我只是使用“setImageDrawable”或“setImageBitmap”。

http://developer.android.com/reference/android/widget/ImageButton。 html

这真的很酷,我的所有用户都很乐意自定义 UI。

但现在,我还想更改按钮的按下/聚焦资源!

现在,当他们点击它时,他们看不到任何东西,而且他们可能点击了 10 次。更成问题的是,这并不直观。

所以我想以编程方式更改按下/聚焦状态...

任何想法建议?

I am using some tweaks that allow the user to change the UI of my application with ressources from their SDCard. That's really easy and nothing special, I just use the "setImageDrawable" or "setImageBitmap".

http://developer.android.com/reference/android/widget/ImageButton.html

That's really cool and all my users are happy to customize the UI.

But now, I would like to also change the pressed/focused ressource of the button!

Now, when they click on it, they cannot see anything and they click maybe 10 times. And more problematic, that's not really intuitive.

So i would like to change also the pressed/focused state programmatically...

Ani idea suggestion?

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

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

发布评论

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

评论(1

清音悠歌 2024-09-17 12:31:59

您必须使所有 ImageButton 具有 StateListDrawable 而不是 BitmapDrawable。

ImageButton ib = new ImageButton(this);
StateListDrawable sl = new StateListDrawable();
sl.addState(new int[] { android.R.attr.state_enabled }, yourDefaultDrawableHere);
sl.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_selected }, yourImageDrawableHere);
ib.setImageDrawable(sl);

You'll have to make all of your ImageButtons have a StateListDrawable instead of BitmapDrawables.

ImageButton ib = new ImageButton(this);
StateListDrawable sl = new StateListDrawable();
sl.addState(new int[] { android.R.attr.state_enabled }, yourDefaultDrawableHere);
sl.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_selected }, yourImageDrawableHere);
ib.setImageDrawable(sl);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文