Как изменить размер шрифта в PreferenceScreen
<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
размером PrefereceCategory
, CheckboxPreference
и android:summary
. Эти теги не имеют атрибута android:textSize
. Может ли кто-нибудь помочь мне, как это получить?
Ответы
Ответ 1
Наконец, я смог решить свою проблему, просто пропустив один макет. Может быть, это кому-то поможет.
Это мой модифицированный preference.xml см. Ниже код. Мы можем применять наши собственные свойства для заголовка и резюме.
preference.xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="First Category"
android:textSize="20px"
android:layout="@layout/mylayout">
<CheckBoxPreference
android:title="Checkbox Preference"
android:defaultValue="false"
android:summary="This preference can be true or false"
android:key="checkboxPref"
android:layout="@layout/mylayout"/>
</PreferenceCategory>
</PreferenceScreen>
mylayout.xml:
<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="40sp"/>
<TextView android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"/>
</LinearLayout>
Пожалуйста, спросите меня, есть ли какие-либо вопросы.... Держите Smiling. Если это полезно, дайте мне один комментарий.
Ответ 2
Для меня макет, размещенный praneetloke, заставил виджет исчезнуть из настроек, у которых есть связанный виджет, например. флажок. Для этого виджета есть LinearLayout с id/widget_frame. Следующие работали для меня, на Android 2.3 до 4.2.2. Единственное изменение, которое мне нужно было сделать, это установить android: visibility = "ушел" на макет, содержащий значок предпочтения, который не был доступен в Gingerbread.
<?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.
Ответ 3
Я изменил Kumar ответ на это для ICS и выше. Я разместил этот макет в значениях-v11 для целевого уровня API API 11 +.
<?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
Вы можете взглянуть на макет, который используется в конкретной платформе в папке макета, расположенной в:
<android-sdk>\platforms\android-<level>\data\res\layout
Макеты настроек начинаются с префикса preference_.
Ответ 5
Взгляните на мой ответ на этот вопрос:
Заголовок Android PreferenceScreen в двух строках.
Вы также можете изменить сам шрифт, если хотите.
Просто добавьте это:
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);
}
Ответ 6
Просто небольшая ревизия кода макета.
"@+ android: id/summary" вызывает Невозможно разрешить символ для меня. поэтому я удаляю знак "+", а код работает
<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="40px"/>
<TextView android:id="@+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26px"/>
</LinearLayout>