Android : Set the background color on preferences.xml

on Monday, September 29, 2014


I'm trying to change the background color on preferences.xml. The default background color is white and the default color for text is black. Is there a way to change it and the text color (the text color that will be used is #6d0505) ??? It also will be applied to the preferences.xml subscreens.


Here, I'm using custom "drawable" to set the background color. The drawable file name is bg_gradient.xml. Here is my code:


res/xml/preferences.xml



<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- That background is also set for this subscreen -->
<PreferenceScreen android:title="Account">

.....
</PreferenceScreen>

.....
<Preference
android:key="pref.about"
android:title="@string/about"
android:summary="@string/app_version">
<intent android:action="android.intent.action.VIEW"
android:data="http://www.example.com/" />
</Preference>
</PreferenceScreen>


res/drawable/bg_gradient.xml



<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<gradient
android:angle="270"
android:gradientRadius="750"
android:endColor="@color/bg_gradient_end"
android:startColor="@color/bg_gradient_start"
android:type="linear" />
</shape>


PreferenceActivity.java


As you can see, I'm using PreferenceActivity (API level 8). Is possible to add the ActionBar with icon? I've added the appcompat_v7 library to this project.



public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
// Then, how to add the ActionBar with icon?
// In this project, I've added the appcompat_v7 library.
}

@SuppressWarnings("deprecation")
@Override
protected void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);

}

@SuppressWarnings("deprecation")
@Override
protected void onPause() {
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {

}
}


I am very grateful to anyone who wants to help me...


0 comments:

Post a Comment