How to get device colors?

≡放荡痞女 提交于 2020-01-05 03:26:08

问题


I have a spinner which is in the Emulator light gray with black text also on HTC devices. On the Motorola Defy the control is dark-gray and the text is white.

How can I get the default text color of the currient device?


回答1:


All the customizations done by carries/manufactures are inside:

  • android:colors
  • android:styles
  • android:themes

If you are using a TextView you can check the default text color by creating a TextView object and calling getTextColors().

Another possibility is checking how the styles are applied to the TextView and using the getResource() method to get the exact color you are looking for.




回答2:


The answer of Macarse goes in the right direction but I uses another way.

I looked in the /platforms/android-X/data/res/values xml files and got the color background_dark which works for me.

Finnally I uses this code:

public class MyAdapter extends ArrayAdapter<SpinnerItem> {
    // ...

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View v = super.getDropDownView(position, convertView, parent);
        TextView tv=(TextView)v.findViewById(android.R.id.text1);
        tv.setTextColor(Resources.getSystem().getColor(android.R.color.background_dark));
        return v;
    }
}


来源:https://stackoverflow.com/questions/8166851/how-to-get-device-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!