change style of widgets (editTextPreference, listPreference, dialogPreference) in android - android

I created an application where I applied theme Theme.Holo.Light. Now I want to change look of my edittexts and dialogs in PreferenceActivity to look like in Theme.Dark. How can I apply different Theme to this particular Widgets?

Related

Define theme with overlay applied

In code, a developer can set a theme using activity.setTheme(R.style.Theme_MyApp) and apply an "overlay" to override select values using activity.getTheme().applyStyle(R.style.ThemeOverlay_SeasonalUpdate, true).
Is there any way to define a theme in XML that extends Theme.MyApp and applies ThemeOverlay.SeasonalUpdate. I would love to do this in XML instead of applying the theme programmatically.

How to declare same attributes for two android themes?

I have to declare some base values for my App (like windowNoTitle).In some activities the Theme.AppCompat.Light theme is needed cause of transparent background images. They need a white background but `` In others the Theme.AppCompat theme will be used for styling.
My App uses androidx.appcompat.widget.Toolbar. So I need to extend a Compat theme. I can't apply the default values as parent and apply the style via theme name.
How to apply the default values to both themes but not repeat my self. Is it possible to declare "style variables"?
Thanks in advance

Is it possible to modify a theme at runtime?

I'd like to dynamically change attributes in this theme: Theme.AppCompat.Light.DarkActionBar. In particular, I'd like to change the colorPrimary, colorAccent, and colorPrimaryDark attributes based on the data being displayed so that particular widgets like EditTexts can be themed appropriately. I know that I'd have to change the theme before setContentView(...) of my Activity but how do I change particular attributes in the theme before I do that?
Edit: From #reVerse's comment linking to this post I know that it's impossible to change a Theme as they are immutable. Is it possible to create a Theme programmatically?

How can I set the style of the EditText.setError() icon to the ones used in the default style while using a different theme?

When you setError on an edittext in an activity which has no theme set, it shows a nice dialog with the error text in it.
How can I set it to that style when using a different theme for the activity like Holo.Light ?

Android preference title/summary text style

I have a couple custom preference items -- one that displays a swatch of the currently selected color, and another one that displays a thumbnail.
I have a custom layout for these that matches up very well, and have found that I can make the text appearance match by using android:textAppearance="?android:attr/textAppearanceLarge" as part of the TextView's xml. The problem is, while these generally look fine, they must not be the appearance the 'official' preferences use, since the colors end up wrong on some devices. In particular I'm porting my application to the Nook Color, and it uses a light grey background and black text color on the preference screen instead of black background/light grey text. My text color in this situation stays the same, but the rest of my layout is themed appropriately.
I'm really unsure what I'm supposed to do here to make my text match up with the 'official' theme. Should I be using obtainStyledAttributes and running though my layout to set things? The tutorials I've seen on using that so far have been really baffling, and it seems like there must be a textAppearance or style I can set in the XML to fix this.
You've to define your own application theme which inherits from the official theme you want. Actually, you can just define a theme MyTheme extending the Theme.Light for example.
Create an res/values/styles.xml file like that:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
</style>
</resources>
Then, you just have to apply your theme using the android:theme attribute of the application entity of your AndroidManifest.xml:
<application android:theme="#style/MyTheme">
[...]
</application>

Categories

Resources