Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a theme for preferences screen

I want the change the look of the preferences screen for an app I am working on. On some phones the preferences are very translucent and it is quite difficult to read the preferences scheme, so I am going to change the visuals for it.

My question is how can I apply a theme to the preferences scheme? Or failing that, how can I change the text color that show up for the various preferences.

In my current version, my preferences layout xml file starts with:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffa0a0a0">

This background color gives me an acceptable gray, but I would prefer to use a theme.

I tried putting a applying a couple of different themes in the preferences xml and the preferences layout xml and none of this has shown any effect. I also tried setting andoid:textColor for the individual preferences items and in layout and that had no effect.

So how does one modify the visuals for the preferences scheme (preferably by using a theme)?

thanks in advance,

Jay

like image 965
jbww Avatar asked Apr 06 '11 05:04

jbww


People also ask

What is the difference between style and theme android?

A style is a collection of attributes that specify the appearance for a single View . A style can specify attributes such as font color, font size, background color, and much more. A theme is a collection of attributes that's applied to an entire app, activity, or view hierarchy—not just an individual view.

How do you apply themes on Android?

Settings. Under Display Options, tap Theme. Select the theme for this device: Light—White background with dark text.

How to use theme in android studio?

To change default themes go to File and click on Settings. A new Settings dialog will appear, like this. Under the Appearance & Behaviour -> Appearance, you will find Theme. Choose the right theme from the drop-down and click on Apply and then Ok.


1 Answers

The basic things are:

  1. A theme for your preferences activity which defines styles for the preference widgets and other things. Take a look at the first theme in themes.xml - this defines the window background, text styles and the preference styles (preferenceScreenStyle, preferenceCategoryStyle etc)
  2. Some styles for each of the preference widgets (which are referenced in themes.xml). For instance in styles.xml they define the Preference.Category and Preference.PreferenceScreen styles.
  3. Apply the theme to your Activity. In your manifest change your opening activity tag for your preferences activity to <activity android:theme="@style/CustomTheme"...

If you want to inherit the default Android styles and then just override some of them, then add parent="@android:style/Theme" to the opening <style... tag of your theme.

Take a look at Applying Styles and Themes for more info.

like image 96
Joseph Earl Avatar answered Sep 20 '22 02:09

Joseph Earl