2010-08-31 50 views
4

我有一个定义,如下面的例子一些优先选择屏幕的XML文件文字大小

<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> 

我希望能够提高个人偏好屏幕的文本的字体大小,但由于在首选项屏幕中没有android:textsize标签,我不知道该如何实现!

回答

7

你可以说,看起来像这样一个TextView布局的xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    style="?android:attr/listSeparatorTextViewStyle" 
    android:textColor="@android:color/white" 
    android:id="@+android:id/title" 
/> 

,并设置自己的喜好类型的布局设计在你的preferences.xml这样的:

<PreferenceCategory 
    android:title="Category Title" 
    android:layout="@layout/pref_category" 
/> 

只要TextView有id @ + android:id/title,你可以使布局看起来像你想要的。还有一种方法可以用我还没弄明白的样式来做到这一点。

+0

真棒...钉了它! :) – Jason 2017-03-27 16:58:08

7

您只需将主题中添加android:textSize喜好屏幕:

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> 

SettingsActivity类:

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类:

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 
     } 
    //..... 
     }