I have created Preference Screen with Text View.User can change Text view style like font,color,size in Preference screen.so it will displayed on Textview which i have created in Preference Screen.but its not working .If its preference Activity ,we can use setContentview,In fragments i don't know how to pass the view..
public final class TestFragment2 extends PreferenceFragment {
static TextView textView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout.customprefernce, null);
textView = (TextView) view.findViewById(R.id.TextViewSample);
final CheckBoxPreference checkboxPref = (CheckBoxPreference) getPreferenceManager()
.findPreference("bold");
checkboxPref
.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// Log.d("MyApp", "Pref " + preference.getKey() +
// " changed to " + newValue.toString());
textView.setTextColor(Color.BLUE);
// Color is not changing.
return true;
}
});
}
I have check box prefernce for changin the color ,but its not changing the color textView.setTextColor(Color.BLUE);
Preferncescreen.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:holo="http://schemas.android.com/apk/res-auto">
<Preference
android:selectable="false"
android:summary="@string/preference_summary"
android:title="@string/preference_title" />
<Preference
android:layout="@layout/customprefernce" />
<PreferenceCategory android:title="@string/preference_base">
<CheckBoxPreference
android:id="@+id/bold"
android:defaultValue="false"
android:key="bold"
android:title="@string/preference_check_box_title" />
<CheckBoxPreference
android:id="@+id/italic"
android:key="italic"
android:defaultValue="false"
android:summaryOff="@string/preference_check_box_summary_off"
android:summaryOn="@string/preference_check_box_summary_on"
android:title="@string/preference_check_box_title" />
</PreferenceCategory>
</PreferenceScreen>
CustomPrefernce.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+id/TextViewSample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Example Tex"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="@+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>