开发者

How to know the colors of a particular Android phone

开发者 https://www.devze.com 2023-02-03 16:29 出处:网络
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.

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) TextViews 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!!


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.


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.


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):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
      android:drawable="@android:drawable/list_selector_background" /> <!-- pressed -->
        <item android:state_focused="true"
      android:drawable="@android:drawable/list_selector_background" /> <!-- focused -->
    <item android:drawable="@android:drawable/list_selector_background" /> <!-- default -->
</selector>

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号