显示按钮按下或未按下的替代方案比选择器更简单?

发布于 2025-01-04 03:53:46 字数 304 浏览 2 评论 0原文

我有一个应用程序,在各个屏幕上有大量按钮。每个按钮都有背景图像和文本(因此 ImageButton 不好)。我知道对于按钮可以处于的不同状态(例如按下和未按下),可以有图像的多个版本,可以将图像的不同版本放入选择器中,然后设置作为选择器的按钮的背景。然而,这意味着我需要为每个图像创建两个版本(我正在考虑的每个不同密度的乘以四),从而使我的 apk 的大小膨胀,并增加相当多的时间来生成重复的图像。

这是更改按钮按下或未按下时的外观的唯一方法(即将其背景设置为链接到两个不同图像的选择器),还是有其他更简单的方法来更改按钮的外观,比如指定按钮的某些内置属性(例如其“黑暗度”)?

I have an application with a large number of buttons across the various screens. Each of the buttons has a background image as well as text (so ImageButton is no good). I am aware that it's possible to have multiple versions of an image for the different states a button can be in (e.g. pressed and not pressed), that it's possible to put the different versions of the image in a selector, and then to set the background of the button to be the selector. However, this means I need to create two versions of each image (times four for each of the different densities I'm considering) and thus bloating the size of my apk as well as adding considerable time to produce the duplicate images.

Is this the only way to change the look of a button for when it's pressed or not (i.e. to set its background to be a selector which links to two different images), or is there some other easier way to change the look of a button, like specifying some built-in property of the button (its 'darkness' for example)?

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

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

发布评论

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

评论(1

旧人九事 2025-01-11 03:53:46

找到了一种显示 View 是否按下的方法,方法是将 View 包装在 FrameLayout 中,给出 FrameLayout一个前景可绘制对象,它是一个选择器,由黑色透明颜色(按下状态)和完全透明颜色(默认状态)组成,然后在FrameLayout 而不是查看。在我的博客上更详细地写了它:

http://adilatwork.blogspot.co.uk/2012/12/android-show-view-as-pressed-without.html

Found one way of showing a View as pressed or not by wrapping the View in a FrameLayout, giving the FrameLayout a foreground drawable which is a selector consisting of a black-ish transparent colour (pressed state) and fully transparent colour (default state), and then setting the click listener on the FrameLayout instead of the View. Wrote it out in greater detail on my Blog here:

http://adilatwork.blogspot.co.uk/2012/12/android-show-view-as-pressed-without.html

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