如何知道特定 Android 手机的颜色
我发现 Android 有许多不同的“主题”,具体取决于设备。例如,在我的 HTC WildFire 上,突出显示颜色是“柠檬绿”,而模拟器的突出显示颜色是橙色。
无论如何,有没有办法知道运行我的应用程序的设备的主界面颜色是什么?
因此,我可以设置(例如)TextView
的背景颜色以匹配设备主题。
编辑:你告诉我这是不可能的,所以...
有什么方法可以用突出显示颜色绘制一个简单的矩形吗?也许是一个无效按钮?
谢谢!!
I've seen there are many different "themes" for the Android, depending on the device. For example on my HTC WildFire the highlight color is a "lime green", and that of the emulator is orange.
Is there anyway to know what are the main interface colors of the device in which my app is running?
So i can set (for example) TextView
s background colors to match the device theme.
EDIT: You told me this is not possible so...
Is there any way to draw a simple rectangle with the highlight color? Maybe a void button?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它实际上并不是指定的颜色,绘图本身实际上是在 HTC、三星等推出的这些修改后的 Android 皮肤上替换的。因此,从编程角度来说,没有直接的方法可以知道配色方案是什么。您最好的选择是简单地使用您自己的配色方案为您的小部件定义您自己的可绘制对象,或者甚至重用原生 Android 中的默认值,但将它们复制到应用程序的可绘制文件夹中,并将它们设置到 StateListDrawable 中,然后将它们应用到您的应用程序中。小部件。这将确保您在所有平台上获得相同的颜色样式,缺点是您的应用程序将与皮肤其余部分的方案不匹配。不过,根据您的应用程序的布局,这可能不是问题。
It's not actually a specified color, the drawables themselves are actually replaced on these modified Android skins that HTC, Samsung, etc. put out. So programmatically, there's no direct way to know what the color scheme will be. Your best bet would be to simply define your own drawables for your widgets with your own color scheme, or even reuse the defaults from stock Android, but copy them to your app's drawable folder, and set them into a StateListDrawable, and apply these to your widgets. This will ensure that you get the same color style on all platforms, with the disadvantage being that your app will not match the scheme of the rest of the skin. Depending on your app's layout, that will likely not be a problem, though.
我认为没有办法让您获得默认的突出显示颜色,但您当然可以通过在布局中的 TextView 上使用“textColorHighlight=#aarrggbb”属性来设置自己的突出显示颜色。
I don't think that there is a way for you to get what the default highlight color is but you can certainly set your own by using the "textColorHighlight=#aarrggbb" attribute on your TextView within the layout.
据我所知,没有办法(我不明白怎么可能真的有办法)。我想您可以在自己的应用程序中拥有一些不同的“主题”,并让用户选择一个,以轻松地至少在某种程度上匹配他们的其他设置。
As far as I know, there isn't a way (I don't see how there could be really). I guess you could have a few different "themes" in your own app and let the user pick one, to easily atleast somewhat match the rest of their setup.
您可以在视图上使用
@android:drawable/list_selector_background
(或代码形式:android.R.drawable.list_selector_background
)。它具有每个默认选择器状态。您还可以在可绘制文件夹中自己创建一个选择器,如下所示(命名为default_highlight.xml):并更改您可能想要自定义的任何选择器。然后,您可以像任何可绘制对象一样使用它,方法是将视图的背景设置为该背景(default_highlight 或任何您所说的名称)。
You can use the
@android:drawable/list_selector_background
(or code form:android.R.drawable.list_selector_background
) on your views. It has each of the default selector states. You can also create a selector yourself in the drawable folder like this (named something like default_highlight.xml):And change any of those that you might want to customize. Then you use it like any drawable by setting the background of a View to that (default_highlight or whatever you call it).