How to change text color of Android's preferences?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to change text color of Android's preferences?

Postby vovs » Mon Feb 07, 2011 3:59 pm

I want to change the look of my Android app's preference screen to white background and dark text color...
In my Activity i set
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class SettingsActivity extends PreferenceActivity
  2. @Override
  3.     public void onCreate(Bundle savedInstanceState) {
  4.         super.onCreate(savedInstanceState);
  5.         setTheme(android.R.style.Theme_Light);
  6.         setTheme(android.R.style.Theme_Light_NoTitleBar);
  7. ........
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


I get white background but text color is too white ((
How can i change text color to black?

Image
vovs
Developer
Developer
 
Posts: 42
Joined: Thu Jan 27, 2011 7:33 pm
Location: Ukraine

Top

Re: How to change text color of Android's preferences?

Postby azekrot » Tue Feb 08, 2011 7:18 pm

The easiest way would be to set the theme (and only one) in the AndroidManifest.xml file.
azekrot
Developer
Developer
 
Posts: 49
Joined: Thu Sep 02, 2010 7:58 pm

Re: How to change text color of Android's preferences?

Postby vovs » Wed Feb 09, 2011 9:23 am

I try so:
Here is my AndroidManifest.xml:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <activity android:name=".view.SettingsActivity"
  2.         android:theme="@android:style/Theme.Light"></activity>
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

background on my SettingsActivity is white and text color is too white ((

Another way:
i create my custom theme:

here is my SettingsActivity.java:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {
  2.        
  3.     /** Called when the activity is first created. */
  4.     @Override
  5.     public void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.         addPreferencesFromResource(R.layout.settings);
  8. .....
  9.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Here is my AndroidManifest.xml:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <activity android:name=".view.SettingsActivity"
  2.         android:theme="@android:style/Theme.Light"></activity>
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Here is my style.xml:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <style name="MyTheme" >
  2.     <item name="@android:textAppearance">@style/MyDefaultTextAppearance</item>
  3.   </style>
  4.        
  5.         <style name="MyDefaultTextAppearance" parent="@android:style/TextAppearance">
  6.             <item name="android:textSize">12sp</item>
  7.             <item name="android:textColor">#000000</item>
  8.             <item name="android:textStyle">bold</item>
  9.           </style>
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


But I get white background and text color is too white ((
vovs
Developer
Developer
 
Posts: 42
Joined: Thu Jan 27, 2011 7:33 pm
Location: Ukraine

Re: How to change text color of Android's preferences?

Postby azekrot » Wed Feb 09, 2011 9:28 pm

Where do you apply the MyTheme style? Do you use any other styles?
I'd suggest to start with something simple and go on from there to see where it breaks.
azekrot
Developer
Developer
 
Posts: 49
Joined: Thu Sep 02, 2010 7:58 pm

Re: How to change text color of Android's preferences?

Postby vovs » Wed Feb 09, 2011 10:22 pm

i am sorry..
i apply MyTheme style in AndroidManifest.xml for SettingsActivity

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. <activity android:name=".view.SettingsActivity"
  2.         android:theme="@android:style/MyTheme"></activity>
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I use other styles too. But for other activities.
vovs
Developer
Developer
 
Posts: 42
Joined: Thu Jan 27, 2011 7:33 pm
Location: Ukraine

Re: How to change text color of Android's preferences?

Postby azekrot » Thu Feb 10, 2011 7:02 pm

Then it should be
Code: Select all
<style name="MyTheme" parent="@android:style/Theme.Light">

You definitely interfere with the default styles somewhere. Just for a hack, try this:
Code: Select all
<style name="MyTheme" parent="@android:style/Theme.Light">
    <item name="android:textColor">#000</item>
</style>

At least you should be able to see the text.
By the way, looking at the source code it appears that preferences use textAppearanceLarge and textAppearanceSmall. Try these instead. Here is your example:
Code: Select all
<style name="MyTheme"  parent="@android:style/Theme.Light>
    <item name="android:textAppearanceSmall">@style/MyDefaultTextAppearance</item>
  </style>
       
    <style name="MyDefaultTextAppearance" parent="@android:style/TextAppearance.Small">
            <item name="android:textSize">12sp</item>
            <item name="android:textColor">#000000</item>
            <item name="android:textStyle">bold</item>
          </style>
azekrot
Developer
Developer
 
Posts: 49
Joined: Thu Sep 02, 2010 7:58 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests