i want use PreferenceScreen
for setting page, i know use EditTextPreferences
and use this text. but i don't know other Objects, for example : i don't know change text color from ListPreference
, or i don't know show/hide text from CheckBoxPreference
.
Attention : Please do not negative. I searched on the internet but could not find an appropriate topic, So here's the question I asked. Please guide me instead of giving a negative rating!
Main Activity code :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
///--- Setting Options
summary_tv = (TextView) findViewById(R.id.main_summary_text);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
String colors = "";
String main_title_text = preferences.getString("setting_title_text", "main_title");
summary_tv.setText(main_title_text);
Boolean main_title_show = preferences.getBoolean("setting_title_show", true);
Preference Activity code :
public class SettingPage extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
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.setting_prefrences);
}
}
}
Preference XML code :
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="setting_title_title_category"
android:title="Title options">
<CheckBoxPreference
android:id="@+id/setting_title_show_id"
android:key="setting_title_show"
android:title="Show Main Title"
android:summary="Show/hide MainPage title" />
<EditTextPreference
android:key="setting_title_text"
android:title="Set Main Title"
android:summary="Change MainPage title"
android:dialogTitle="Change Title"
android:dialogMessage="Change title please..."/>
</PreferenceCategory>
<PreferenceCategory
android:key="setting_title_font_category"
android:title="Font options">
<ListPreference
android:key="setting_title_font_color"
android:title="Title font colors"
android:summary="Change title font colors"
android:entries="@array/colors"
android:entryValues="@array/colors"
android:dialogTitle="Change font color" />
</PreferenceCategory>
<RingtonePreference
android:title="tes"/>
</PreferenceScreen>
String XML code :
<resources>
<string name="app_name">1-MyTestDb Project</string>
<string name="title_activity_settings">Settings</string>
<string-array name="colors">
<item>White</item>
<item>Black</item>
<item>Primary</item>
</string-array>
</resources>
How can use this preferences in java code. for example change TextView
color with ListPreference
?
EditTextPreference
, but i can't useCheckboxPreference
,ListPreference
! can you send me how to use this? for example change TextView color withListPreference
? Thanks <3 – Nanete