如何在偏好片段中改变文本样式

我已经创build了文本视图的偏好屏幕。用户可以改变文本视图样式喜欢字体,颜色,大小在首选项screen.so它将显示在文本视图,我已经在偏好屏幕创build,但它不工作。如果它的偏好活动,我们可以使用setContentview,在片段我不知道如何通过视图..

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; } }); } 

我有checkbox为改变颜色,但它不改变颜色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> 

Solutions Collecting From Web of "如何在偏好片段中改变文本样式"