显示按钮按下或未按下的替代方案比选择器更简单?
我有一个应用程序,在各个屏幕上有大量按钮。每个按钮都有背景图像和文本(因此 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了一种显示
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 theView
in aFrameLayout
, giving theFrameLayout
aforeground
drawable which is aselector
consisting of a black-ish transparent colour (pressed state) and fully transparent colour (default state), and then setting the click listener on theFrameLayout
instead of theView
. Wrote it out in greater detail on my Blog here:http://adilatwork.blogspot.co.uk/2012/12/android-show-view-as-pressed-without.html