首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在PreferenceScreen中更改字体大小

如何在PreferenceScreen中更改字体大小
EN

Stack Overflow用户
提问于 2011-03-17 12:21:57
回答 4查看 31K关注 0票数 21
代码语言:javascript
复制
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory
        android:title="First Category"
        android:textSize="20px">

        <CheckBoxPreference
            android:title="Checkbox Preference"
            android:defaultValue="false"
            android:summary="This preference can be true or false"
            android:key="checkboxPref" />

    </PreferenceCategory>
</PreferenceScreen>

我需要改变android:title字体大小的PrefereceCategoryCheckboxPreferenceandroid:summary的大小。这些标记没有任何android:textSize属性。有谁能帮我弄到这个吗?

EN

回答 4

Stack Overflow用户

发布于 2013-04-17 02:08:00

对我来说,praneetloke发布的布局让小部件从有关联小部件的首选项中消失了,例如复选框。小部件需要一个id为/ widget _ LinearLayout的框架。下面的方法适用于我,在Android2.3到4.2.2之间。我需要做的唯一更改是在包含首选项图标的布局上设置android:visibility=“消失”,这在姜饼中是不可用的。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingLeft="8dip"
    android:paddingRight="?android:attr/scrollbarSize" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:minWidth="0dp"
        android:orientation="horizontal"
        android:visibility="gone" >

        <ImageView
            android:id="@+android:id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:minWidth="48dp"
            android:paddingRight="8dip" />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingBottom="6dip"
        android:paddingRight="8dip"
        android:paddingTop="6dip" >

        <TextView
            android:id="@+android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@android:id/title"
            android:layout_below="@android:id/title"
            android:maxLines="4"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary" />
    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->

    <LinearLayout
        android:id="@+android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:minWidth="48dp"
        android:orientation="vertical" />

</LinearLayout>

引用:布局中使用的默认尺寸在这里是GrepCode /res/values/dimens.xml。实际的首选项布局在这里是GrepCode /res/layout/preference_holo.xml。请注意,还有一个称为preference.xml的非全息版本。

票数 13
EN

Stack Overflow用户

发布于 2012-12-05 09:38:54

我在ICS及更高版本中修改了Kumar的答案。我将此布局放在values-v11中,以实现目标设备的API级11+。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView android:id="@+android:id/title"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="18dp"
        android:textColor="?android:attr/textColorPrimary"
        android:paddingLeft="8dip"/>

    <TextView android:id="@+android:id/summary"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="14dp"
        android:textColor="?android:attr/textColorSecondary"
        android:paddingLeft="8dip"/>

</LinearLayout>
票数 4
EN

Stack Overflow用户

发布于 2013-11-30 02:35:03

看看我对这个问题的回答:Android PreferenceScreen title in two lines

如果需要,您还可以更改字体本身。只需添加以下内容:

代码语言:javascript
复制
Typeface myTypeface = Typeface.createFromAsset(textView.getContext().getAssets(),"fonts/your_font_name.ttf");
    if (textView != null) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getContext().getResources().getDimension(R.dimen.text_size_from_dimen));
        textView.setTypeface(myTypeface);
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5334828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档