Android:在自定义按钮中使用默认突出显示颜色
我想在我的 Android 应用程序中使用按钮,但我想自定义它的外观。但是,我希望按钮的突出显示和选定颜色与默认颜色相同(即深橙色和浅橙色渐变,或主题颜色提供的任何颜色)。
无论如何,是否可以获取默认的突出显示/选定的可绘制对象并将其用作选定和突出显示状态上的按钮的填充?
谢谢!
I want to use a Button in my android app but I want to customize how it looks. However, I want the highlight and selected colors of the button to be the same as the default colors (i.e. the dark and light orange gradients, or whatever the theme color supplies).
Is there anyway to get the default highlight/selected drawables and to use that as the fill for my buttons on the selected and highlighted states?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要求两个不同的东西,您想要绘图还是颜色代码?
无论如何,您可以在这里找到可绘制对象的名称: http://androiddrawableexplorer.appspot.com/
我不知道你是否可以直接从你的应用程序使用它们,或者你是否必须先将它们保存到你的drawables文件夹中,但你可以在你的sdk中找到它们。如果您想要颜色代码,请使用 gimp 从图片中提取它们。
You are asking for two different things, do you want the drawables or the colorcode?
Anyway, you can find the name of the drawables here: http://androiddrawableexplorer.appspot.com/
I don't know if you can use them directly from your app or if you have to save them to your drawables folder first, but you can find them in your sdk. If you want the colorcodes, use gimp to extract them from the pictures.
看来您可以在选择器内将选择器用作可绘制的!
(您可以或不应该使用
@android:drawable/btn_default_selected
,因为它是私有的)这意味着您可以编写自己的选择器,并为您想要默认行为的项目使用整个默认的 android 选择器。
我使用了这个选择器
并将其添加到线性布局的背景中。
我不知道为什么,但这也弄乱了填充/边距,这就是为什么我将它们设置为 0。
结果是,您的父背景颜色处于未按下状态,而 android 背景颜色处于按下状态。
It seems that you can use a selector as drawable inside a selector!
(You can or should not use
@android:drawable/btn_default_selected
, because it is private)This meens that you can write your own selecter and use the whole default android selector for the items you want the default behavior for.
I used this selector
And added it to as background to a linear layout.
I don't know why, but this messed up the padding/margin as well, thats why i set them to 0.
The Result is that you have the parent background color in the unpressed state and the android background color for the pressed state.
选择器就是您要寻找的。谷歌周围的教程。这是一个。
我假设你可以在 Android 源代码中找到默认选择器。
Selectors are what you're looking for. Google around for tutorials. Here's one.
I Suppose you can find the Default Selector in the Android Source Code.