问题
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