gpt4 book ai didi

android - PreferenceScreen 中的文本大小

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:36:39 29 4
gpt4 key购买 nike

我有一个 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 标签,我不知道如何实现!

最佳答案

您可以简单地在您的主题中添加 android:textSize 用于首选项屏幕:

例如:

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

关于android - PreferenceScreen 中的文本大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3611809/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com