Change Background Color Preferences

I have a PreferenceCategory , xml file, and I defined all its preferences, I call it from a class that extends PreferenceActivity . I can not set the background of my settings screen, this screen is displayed using the xml file shown below. Look that I already defined android:background="#041A37" , but the default color still remains: black.

 public class MyPreferenceActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { Context mContext=super.getBaseContext(); super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.preference); //v.setBackgroundColor(Color.rgb(4, 26, 55)); } } 



preference.xml

 <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:background="#041A37" > <PreferenceCategory> <com.dropcall.SeekBarPreference android:background="#041A37" android:defaultValue="5" android:key="@string/Interference_Delay" android:progressDrawable="@drawable/seekbardrawable" android:title="Seconds Delay until intereference" /> <com.dropcall.SeekBarPreference2 android:defaultValue="30" android:key="@string/Drop_Delay" android:progressDrawable="@drawable/seekbardrawable" android:title="Seconds delay until drop" /> <CheckBoxPreference android:background="@drawable/state_normal" android:defaultValue="true" android:key="@string/Drop_Option" android:title="Close after call drop" /> <CheckBoxPreference android:background="@drawable/state_normal" android:defaultValue="true" android:key="@string/Timer_Option" android:title="Start timers on launch" /> </PreferenceCategory> </PreferenceScreen> 



Although I set android:background="#041A37" in each file, the background does not turn blue or any other color. The default color remains black. How to change the background color. Please let me know any pointers / tips if you encounter the same problem, let me know what changes you made to set the background color.

+43
android android-emulator
Aug 23 '10 at 19:54
source share
7 answers

It worked for me

 getListView().setBackgroundColor(Color.TRANSPARENT); getListView().setCacheColorHint(Color.TRANSPARENT); getListView().setBackgroundColor(Color.rgb(4, 26, 55)); 
+39
Aug 24 '10 at 20:17
source share

You can define a topic and then set this for your PreferenceActivity in the manifest. Then your theme can determine the background color or image of the window, if you prefer it.

manifest:

  <activity android:label="@string/app_label" android:name=".client.PreferencesActivity" android:theme="@style/PreferencesTheme"> <intent-filter> </intent-filter> </activity> 

Then add the theme to your styles.xml

 <style name="PreferencesTheme"> <item name="android:windowBackground">@drawable/background_image</item> <item name="android:background">#FFEAEAEA</item> </style> 

The above snippet contains both the background color and the background image that determines how to do this.

+74
May 11 '11 at 14:05
source share

Another color issue is that you create a theme for activity preferences and set the background color as a list:

 <style name="PrefsTheme" parent="@android:style/Theme.Black.NoTitleBar"> <item name="android:windowBackground">@color/prefs_bg</item> <item name="android:textColor">@color/text_color</item> <item name="android:listViewStyle">@style/listViewPrefs</item> </style> <style name="listViewPrefs" parent="@android:style/Widget.ListView"> <item name="android:background">@color/prefs_bg</item> <item name="android:cacheColorHint">@color/prefs_bg</item> </style> 
+21
Jan 24 2018-12-12T00:
source share

android:background not an available attribute, as per the documentation .

Perhaps you could flag PreferenceActivity to achieve a color change, although I have not tried it because I want my settings to look like the rest of Android, to improve the usability of the application.

+6
Aug 23 '10 at 21:45
source share

Or you can also make drawable as background:

getListView () <strike> setBackgroundDrawableudap> (GetResources () getDrawable (R.drawable.bluegradient).) ;.

Note. setBackgroundDrawable() deprecated. Use setBackground() .

getListView () setBackground (GetResources () getDrawable (R.drawable.bluegradient).) ;.

+3
Oct 06 2018-10-06
source share

Please specify a linear layout with attached text and specify a background color and attach this xml to the preferences category using the layout property.

 <PreferenceCategory android:layout="@layout/preftitle" > 

If preftitle is an xml that has a linear layout and text view.

0
Apr 09 2018-12-12T00:
source share

Go to res>values>styles.xml> and add this code to your <style > </style> style should be the main application theme in this @color/activ there are color resources added to the colors.

 <style name="app_theme" parent="@android:style/Theme"> <item name="android:windowBackground">@color/activ</item> <item name="android:windowContentOverlay">@drawable/title_bar_shadow</item> <item name="android:listViewStyle">@style/TransparentListView</item> </style> 

if you use app_theme style tag name then add something like your manifest

 <application android:name=".XXXXXX" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/app_theme" > //here 

If you want to change your background

0
Jun 24 '15 at 6:58
source share



All Articles