Android preference header / summary text

I have a couple of custom preference items β€” one that displays a sample of the currently selected color, and another that displays a thumbnail.

I have a custom layout for them that fits very well, and found that I can make text match using android: textAppearance = "? Android: attr / textAppearanceLarge" as part of the TextView xml. The problem is that although they tend to look great, they should not be what the β€œofficial” preferences are used, because on some devices the colors are wrong. In particular, I port my application to Nook Color, and it uses a light gray background and black text on the preferences screen instead of black or light gray text. My text color in this situation remains the same, but the rest of my layout is consistent with the theme.

I'm really not sure what I should do here so that my text matches the β€œofficial” theme. Should I use getStyledAttributes and work, although my layout is for installation? The tutorials I've seen using this so far have been really perplexing, and it seems like the textAppearance or style should be set in the XML document to fix this.

+6
source share
1 answer

You must define your own application theme, which inherits from the official theme you want. In fact, you can simply define a MyTheme theme that extends, for example, Theme.Light .

Create a res/values/styles.xml :

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyTheme" parent="@android:style/Theme.Light"> </style> </resources> 

Then you just need to apply your theme using the android:theme attribute of the application object of your AndroidManifest.xml :

 <application android:theme="@style/MyTheme"> [...] </application> 
0
source

Source: https://habr.com/ru/post/895189/


All Articles