addPreferencesFromResource - android

I know this might be a duplicate from: What to use instead of "addPreferencesFromResource" in a PreferenceActivity?
But I still can not get the code to work and would appreciate some help. I can not get the:
"addPreferencesFromResource(R.xml.preferences);" to work.
preferences is not resolved, even though it is in the R.xml folder.
I followed the example in the above link to the letter.
Please help!!
package com.example.oasisreference;
import android.R;
import android.R.xml;
//import android.annotation.TargetApi;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
public class Prefs extends PreferenceActivity {
#Override
protected void onCreate(final Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
#Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}
preferences.xml in the Res.xml folder
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:title="User Name"
android:key="name"
android:summary="Enter your name"
></EditTextPreference>
<CheckBoxPreference
android:title="Euro Currency"
android:defaultValue="false"
android:key="euro"
android:summary="Check for Use Cost Calculator to be in Euros/Liters">
</CheckBoxPreference>
</PreferenceScreen>
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/aboutUs"
android:title="About the Author">
</item>
<item
android:id="#+id/preferences"
android:title="Preferences">
</item>
<item
android:id="#+id/exit"
android:title="Exit">
</item>
</menu>

delete import android.R
it will work

The answer is, it's not actually deprecated....
They just want you to use preferenceFragments (see below)
It turns out that it's the same routine name but it is instantiated as part of a preferenceFragment which is a different class. There's it's not deprecated. This is subtle but the examples at the developer website reference it from within a preference fragment. Paste the deprecated call into a preferenceFragment class and see for yourself the deprecation goes away
In the preferenceFragment class declaration:
package android.preference;
public abstract class PreferenceFragment extends android.app.Fragment {
// ...
public void addPreferencesFromIntent(android.content.Intent intent) {
/* compiled code */
}
  
public void addPreferencesFromResource(int preferencesResId) {
/* compiled code */
}
// ...
and in the other class
package android.preference;
public abstract class PreferenceActivity extends android.app.ListActivity implements android.preference.PreferenceFragment.OnPreferenceStartFragmentCallback {
/**
* #deprecated
*/
#java.lang.Deprecated
public void addPreferencesFromResource(int preferencesResId) {
/* compiled code */
}

Add #SuppressWarnings("deprecation") before OnCreate method.

Related

Icons in Preference Fragment not adapting to night mode

I'm wirting a android app and wanted to make a SettingsActivity.
The problem I have that my vector drawable won't adapt it's color to night or day theme.
ic_palette_black_24dp.xml:
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#color/icon_color_on_surface" android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9c0.83,0 1.5,-0.67 1.5,-1.5 0,-0.39 -0.15,-0.74 -0.39,-1.01 -0.23,-0.26 -0.38,-0.61 -0.38,-0.99 0,-0.83 0.67,-1.5 1.5,-1.5L16,16c2.76,0 5,-2.24 5,-5 0,-4.42 -4.03,-8 -9,-8zM6.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,9 6.5,9 8,9.67 8,10.5 7.33,12 6.5,12zM9.5,8C8.67,8 8,7.33 8,6.5S8.67,5 9.5,5s1.5,0.67 1.5,1.5S10.33,8 9.5,8zM14.5,8c-0.83,0 -1.5,-0.67 -1.5,-1.5S13.67,5 14.5,5s1.5,0.67 1.5,1.5S15.33,8 14.5,8zM17.5,12c-0.83,0 -1.5,-0.67 -1.5,-1.5S16.67,9 17.5,9s1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5z"/>
</vector>
values/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="icon_color_on_surface">#000000</color>
</resources>
values-night/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="icon_color_on_surface">#FFFFFF</color>
</resources>
And in my root_preferences.xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root_preferences">
<PreferenceCategory android:title="#string/title_preference_design">
<ListPreference
android:entries="#array/preference_list_theme"
android:entryValues="#array/preference_list_theme_values"
android:icon="#drawable/ic_palette_black_24dp"
android:key="list_preference_theme"
android:tint="#color/icon_color_on_surface"
android:tintMode="src_atop"
android:title="#string/preference_category_theme"
app:icon="#drawable/ic_palette_black_24dp" />
</PreferenceCategory>
</PreferenceScreen>
[Edit]
Here also my SettingsActivity.java that is basicly the default by AndroidStudio:
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import java.util.ArrayList;
public class SettingsActivity extends AppCompatActivity {
private ColorHelper colorHelper;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
public static class SettingsFragment extends PreferenceFragmentCompat {
#Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
// Indicate here the XML resource you created above that holds the preferences
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
}
}
[/EDIT]
As you can see in root_preferences.xml I already tried setting it by android:tint="" and android:tintMode="" but no matter what I do the icon color stayes white.
In other Activities the workaround with android:tint="" does work.
I hope someone can help me with this.
Thanks
The way to go about this is to define a resource attribute to the fillColor. Also, if I recall correctly, the tint that you have defined in your vector's XML is either overriding or has no effect on SVG drawables. My drawables don't have the tint color set, and the fillColor property is dynamic for all drawables.
Below, android:fillColor="?android:attr/textColorSecondary" is defined by Android System and is already handled by Theme.MaterialComponents.DayNight. You can also create your own attr values.
<vector
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="?android:attr/textColorSecondary"
android:pathData="..."
/>
</vector>
Depending on your use case, you can also use textColorPrimary, textColorTertiary from ?android:attr for different shades.

Styling SeekBarPreference to be consistent with SwitchPreference

I have the following preferences in my preferences.xml:
<SwitchPreference
android:summary="Lorum ipsum dolor sit amet"
android:title="Frobulate" />
<SeekBarPreference android:title="Marglins"/>
<SwitchPreference android:title="Bromzuling" />
The problem with this is that this renders Marglins with a very different style as the titles of the SwitchPreferences:
Is there something I can put in my styles.xml to make the titles look the same in font size, color, alignment etc.?
In your theme, try setting
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
In my mock-up, this shows the following:
This is using com.android.support:preference-v7:27.1.1. Since this is the look that you are looking for, use this library if you can.
Make sure that you are consistently using the preference support library and not mixing things up; otherwise, things make not look/work as expected.
Here is a small app that demonstrates styling of the SeekBar preference. The app doesn't really do anything other than display the preferences. This app show the same display as shown above.
AndroidManifest.xml
Nothing fancy here.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.preferencecustomlayout">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.example.preferencecustomlayout.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- Theme for the preferences -->
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
</resources>
app_preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.SwitchPreferenceCompat
android:key="switchPreference1"
android:summary="Lorum ipsum dolor sit amet"
android:title="Frobulate" />
<android.support.v7.preference.SeekBarPreference
android:key="seekBarPreference"
android:title="Marglins" />
<android.support.v7.preference.SwitchPreferenceCompat
android:key="switchPreference1"
android:title="Bromzuling" />
</android.support.v7.preference.PreferenceScreen>
MainActivity.java
Notice all the "v7" imports at the top. Don't let these get away. If things aren't working, check that you are still using the support library.
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceFragmentCompat;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
Fragment preferenceFragment = new PrefsFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.prefContainer, preferenceFragment);
ft.commit();
}
}
public static class PrefsFragment extends PreferenceFragmentCompat {
#Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.app_preferences);
}
}
}
activity_main.xml
Just a home for the preference fragment.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/prefContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.preferencecustomlayout.MainActivity" />
As for eliminating the numeric display from the seekbar, that is going to be a little more involved. According to the SeekBarPreference documentation:
The seekbar value view can be shown or disabled by setting showSeekBarValue attribute to true or false, respectively.
Unfortunately, setting this value in the app_preferences.xml file gives an "is private" error. There is also no public method, that I have seen, to set the internal variable that controls this. You could subclass SeekBarPreference, override onBindViewHolder() as follows:
MySeekBarPreference.java
import android.content.Context;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.preference.SeekBarPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
public class MySeekBarPreference extends SeekBarPreference {
public MySeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public MySeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public MySeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MySeekBarPreference(Context context) {
super(context);
}
#Override
public void onBindViewHolder(PreferenceViewHolder view) {
super.onBindViewHolder(view);
TextView seekBarValueTextView = (TextView) view.findViewById(R.id.seekbar_value);
seekBarValueTextView.setVisibility(View.GONE);
}
}
The above custom seek bar preference class will just get rid of the seek bar value. Change the seek bar definition in app_preferences.xml to:
<com.example.preferencestyleseekbar.MySeekBarPreference
android:key="seekBarPreference"
android:title="Marglins" />
and you will see that the value is no longer shown.
Preferences are generally a mess. I have found a very good series of articles by Jakob Ulbrich regarding preferences and getting them to work and look like material design. You may find it helpful to check them out.
For me, the solution was to use com.android.support:preference-v14 instead of v7. This allowed me to use PreferenceThemeOverlay.v14.Material, which otherwise was not accessible.

Switch to a nested PreferenceScreen from activity

How do I open up into a nested PreferenceScreen to a particular preference from an activity (such as through an intent)?
Example:
<PreferenceScreen
...
<!-- opens a subscreen of settings -->
<PreferenceScreen
android:key="sub_menu_key"
android:persistent="false"
android:title="Submenu">
...
<PreferenceCategory
android:key="category_key"
android:title="Category">
...
<Preference
android:key="tos_key"
android:title="Terms of Service" />
...
</PreferenceCategory>
</PreferenceScreen>
...
Is there a way to open directly to where "Terms of Service" is visible.
You just need to delare the specified Preference class in your onResume() method. In my case I was using SwitchPreference class, therefore the code would be like - SettingsActivity.class
public static class PrivacyPreferenceFragment extends PreferenceFragment {
public SwitchPreference switchPreference;
#Override
public void onResume() {
super.onResume();
switchPreference = (SwitchPreference) findPreference("privacy_notice_check");
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_privacy);
setHasOptionsMenu(true);
}
}
Then in the activity where you want to use the PreferenceFragment value, just use the SharedPreference object to call the values and trigger it.
If you want the SharedPreference logic just comment below.
From an Activity (es: Main Activity) you can use an explicit intent
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button goToPreference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
goToPreference = (Button) findViewById(R.id.goToButton);
goToPreference.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// when you click go to Preference
Intent intent = new Intent( MainActivity.this, UserSettingsActivity.class);
startActivity(intent);
}
});
}
}
Layout: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="it.uniba.di.ivu.di.sms16.gruppox.examplesettings.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go To Preference"
android:id="#+id/goToButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
UserSettingsActivity is an activity that extends PreferenceActivity and allows you to view preference
import android.content.SharedPreferences;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.os.Bundle;
public class UserSettingsActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("lenguage_preference"))
{
// TO DO
}
}
#Override
protected void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
#Override
protected void onPause() {
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
}
settings.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Lenguage">
<ListPreference
android:key="lenguage_preference"
android:title="Change Lenguage"
android:summary="Choose yout language"
android:entries="#array/entries_list_preference2"
android:entryValues="#array/entryvalues_list_preference2"
android:dialogTitle="choose favourite language" />
</PreferenceCategory>
<PreferenceCategory
android:title="Distance">
<ListPreference
android:key="distance_preference"
android:title="Distance"
android:summary="Change distance"
android:entries="#array/entries_list_preference"
android:entryValues="#array/entryvalues_list_preference"
android:dialogTitle="choose favourite distance" />
</PreferenceCategory>
arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="entries_list_preference"
translatable="false">
<item>2 (km)</item>
<item>1 (km)</item>
<item>500 (m)</item>
<item>200 (m)</item>
</string-array>
<string-array name="entryvalues_list_preference"
translatable="false">
<item>2000</item>
<item>1000</item>
<item>500</item>
<item>200</item>
</string-array>
<string-array name="entries_list_preference2"
translatable="false">
<item>Italian</item>
<item>English</item>
<item>French</item>
</string-array>
<string-array name="entryvalues_list_preference2"
translatable="false">
<item>it</item>
<item>en</item>
<item>fr</item>
</string-array>
Is there a way to open directly to "Terms of Service"?
I think you can refer to How to open or simulate a click on an android Preference, created with XML, programmatically?

Android - Placing a ListView in Preferences Page

I have a preferences page in my application. As there is no Multiple Choice ListPreference (There's one after API Level 11) I want to put a ListView at preferences page. But the preferences.xml doesn't let me to insert a Linear Layout.
Here's my preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Auto Refresh Settings">
<CheckBoxPreference
android:title="Auto Refresh"
android:defaultValue="false"
android:summary="Enable / Disable Auto Refresh"
android:key="checkboxPref" />
<ListPreference
android:title="Auto Refresh Frequency"
android:summary="Select the frequency of Auto Refresh"
android:key="listPref"
android:defaultValue="20"
android:entries="#array/listArray"
android:entryValues="#array/listValues" />
</PreferenceCategory>
</PreferenceScreen>
This is how it looks:
What I want:
:
Lastly my Settings.java (preferences):
package com.sarkolata.coding;
import android.content.Context;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.widget.Toast;
public class Settings extends PreferenceActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
final Preference ListPref = (Preference) findPreference("listPref");
final Preference CheckPref = (Preference) findPreference("checkboxPref");
if(PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getBoolean("checkboxPref", false)) {
ListPref.setEnabled(false);
}
ListPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Main.update_tick = Integer.parseInt(newValue.toString()) * 1000;
return true;
}
});
CheckPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(newValue.toString() == "true")
{
ListPref.setEnabled(false);
} else {
ListPref.setEnabled(true);
}
if(newValue.toString() == "true") {
Main.refreshAllServers(Main.context, Main.bcontext,"start");
} else {
Main.refreshAllServers(Main.context, Main.bcontext,"stop");
}
return true;
}
});
}
}
I don't know if is is clever to add a ListView inside a preference pane because the PreferenceActivity already uses a ListView to show the many preferences. Perhaps you want to use a MultiSelectListPreference, preference that allows you to do multiple selection. You can see an example at http://blog.350nice.com/wp/archives/240

Text size within an PreferenceScreen

I have xml file that defines some preference screens like the following example
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="root_preferencescreen">
<PreferenceScreen android:key="general_sett" android:title="general settings" />
....
<PreferenceScreen android:key="extras_sett" android:title="extras settings" />
</PreferenceScreen>
I would like to be able to increase the font size for the text of the preference screen , but because the within a preference screen there is no android:textsize tag , i have no idea how to accomplish that !
You can simply add android:textSize inside your theme for preference screen:
e.g :
<style name="settingsTheme" parent="PreferenceThemeOverlay">
<item name="colorAccent">#color/color_ten</item>
<item name="android:background">#color/colorPrimaryLight</item>
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
<item name="android:textColorPrimary">#color/colorTextBodyLight</item>
<item name="android:textColorSecondary">#color/colorTextCaptionLight</item>
<item name="android:textSize">14sp</item>
</style>
Your SettingsActivity class :
public class SettingsActivity extends AppCompatActivity {
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
toolbar = (Toolbar)findViewById(R.id.toolbar_settings);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction()
.replace(R.id.bodylayout, new PrefsFragment())
.commit();
}
#Override
protected void onPause() {
super.onPause();
}
}
PrefsFragment class :
public class PrefsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
#Override
public void onCreatePreferences(Bundle bundle, String s) {
}
#Override
public void onCreate(Bundle savedInstanceState) {
final Context myContext = this.getActivity();
//set your theme
myContext.setTheme(R.theme.settingsTheme);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settingspreference);
//do other stuffs
}
//.....
}
You can make a TextView layout xml that looks something like this:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/listSeparatorTextViewStyle"
android:textColor="#android:color/white"
android:id="#+android:id/title"
/>
and set the layout of your preference category in your preferences.xml like this:
<PreferenceCategory
android:title="Category Title"
android:layout="#layout/pref_category"
/>
As long as the TextView has the id #+android:id/title you can make the layout look however you want. There is also a way to do this with styles that I haven't quite figured out.

Categories

Resources