如何更改首选项的字体大小?

问题描述 投票:0回答:3

我不知道如何更改一些首选项的字体大小。我尝试过this post但它没有用。完成后,我的图标没有显示出来。这就是它现在的样子,但我认为偏好的标题太大了。这是我的屏幕目前的样子:

Image of the screen

这是我的pref_headers.xml xml文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference
        android:key="@string/key_pref_general"
        android:title="@string/label_pref_general"
        android:icon="@drawable/ic_person"/>

        <Preference
            android:key="@string/key_pref_categories"
            android:title="@string/label_pref_categories"
            android:icon="@drawable/ic_list"/>

        <Preference
            android:key="@string/key_pref_productivity"
            android:title="@string/label_pref_productivity"
            android:icon="@drawable/ic_chart"/>

        <Preference
            android:key="@string/key_pref_delete"
            android:title="@string/label_pref_delete"/>


</PreferenceScreen>
android xml android-preferences
3个回答
1
投票

我有一个解决方案。您可以通过管理布局文件来更改特定首选项的字体大小。

这是您编辑的pref_headers.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
    android:key="general"
    android:title="General"
    android:icon="@drawable/ic_person_black_24dp"
    android:layout="@layout/font_layout"/>

<Preference
    android:key="categories"
    android:title="Categories"
    android:icon="@drawable/ic_list_black_24dp"
    android:layout="@layout/font_layout"/>

<Preference
    android:key="productivity"
    android:title="Productivity"
    android:icon="@drawable/ic_timeline_black_24dp"
    android:layout="@layout/font_layout"/>

<Preference
    android:key="delete_this_accnt"
    android:title="Delete this Account"
    android:layout="@layout/font_layout"/>
</PreferenceScreen>

这是layout(font_layout.xml)文件,您可以从中更改字体大小或要更改的任何属性,如颜色等:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
    android:id="@android:id/icon"
    android:layout_width="40dp"
    android:paddingStart="4dp"
    android:paddingEnd="4dp"
    android:layout_height="40dp" />

<TextView
    android:id="@android:id/title"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:textColor="#201f1f"
    android:layout_height="wrap_content"
    android:textSize="18sp" />
</LinearLayout>

希望这可以帮助!


0
投票

试试这个

    <PreferenceCategory
    android:title="Category"
    android:textSize="20px">

    <Preference
    android:key="@string/key_pref_general"
    android:title="@string/label_pref_general"
    android:icon="@drawable/ic_person"/>

    <Preference
        android:key="@string/key_pref_categories"
        android:title="@string/label_pref_categories"
        android:icon="@drawable/ic_list"/>

    <Preference
        android:key="@string/key_pref_productivity"
        android:title="@string/label_pref_productivity"
        android:icon="@drawable/ic_chart"/>

    <Preference
        android:key="@string/key_pref_delete"
        android:title="@string/label_pref_delete"/>

</PreferenceCategory>

0
投票

你也可以改变自己的风格

 <!-- Custom Preference Theme inherits from the v14 support library Material Theme -->
<style name="AppPreferenceTheme" parent="@style/PreferenceThemeOverlay.v14.Material">
    <item name="android:textSize">14sp</item>
</style>

<!-- And set preference Theme in your Main Theme-->
<style name="YourTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="preferenceTheme">@style/AppPreferenceTheme</item>
</style>
© www.soinside.com 2019 - 2024. All rights reserved.