Text size within an PreferenceScreen

后端 未结 2 700
半阙折子戏
半阙折子戏 2021-02-10 08:52

I have xml file that defines some preference screens like the following example



        
相关标签:
2条回答
  • 2021-02-10 09:18

    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
            }
        //.....
            }
    
    0 讨论(0)
  • 2021-02-10 09:20

    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.

    0 讨论(0)
提交回复
热议问题