Увеличение заголовка CheckboxPreference и размера сводного текста, а также свечение записи предпочтения

Привет, я работаю над настройками сообщений в качестве предпочтения.

Я пытаюсь изменить размер шрифта android:title и android:summary text в CheckboxPreference.

введите здесь описание изображения

Для этого я пробую приведенный ниже код

   <PreferenceCategory
    android:key="prefcategory1"
    android:title="GENERAL SETTINGS..." >

    <CheckBoxPreference
        android:defaultValue="false"
        android:enabled="true"
        android:key="checkBoxdelete"
        android:layout="@layout/mylayout"     <!--linking it to mylayout.xml -->
        android:summary="Deletes old messages as limits are reached"
        android:title="Delete old messages" />
  </PreferenceCategory>

и mylayout.xml

<TextView android:id="@+android:id/title"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="8dp"
    android:textColor="#FFFFFF"
    android:textSize="30px"
    android:textStyle="bold"/>  

<TextView android:id="@+android:id/summary"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="8dp"
    android:textColor="#FFFFFF"
    android:textSize="20px"
    android:textStyle="bold"/>

Используя это, размер текста увеличивается, как показано на снимке экрана ниже. Но я не вижу флажок. Как мне решить эту проблему?

введите здесь описание изображения


person sanjana    schedule 13.09.2013    source источник


Ответы (4)


Большинство ответов здесь совершенно неверны или слишком сложны для реализации, когда есть более простые способы сделать то же самое.

Только для будущих читателей. Вы можете изменить textSize/ textColor в своем styles.xml

   <style name="PreferencesTheme" parent="@android:style/Theme.Black">
            <item name="android:textSize">34sp</item>
            <item name="android:textColorSecondary">#000000</item>
            <item name="android:textColorPrimary">#000000</item>
    </style>

где textColorPrimary изменит цвет заголовка checkBoxPreference, а textColorSecondary изменит цвет сводки.

person bhaskarc    schedule 16.04.2014
comment
Это меняет не только текст на экране настроек - person Denny; 10.02.2018

Вам нужно добавить флажок в свой собственный макет следующим образом:

<CheckBox
    android:id="@+android:id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:focusable="false" />
person tpbapp    schedule 13.12.2013

Чтобы увеличить размер текста в флажке, я использовал пользовательский класс.

import android.content.Context;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import android.widget.TextView;


@SuppressWarnings("unused")
public class CustomCheckBoxPreference extends CheckBoxPreference {

    private Context mContext;

    public CustomCheckBoxPreference(Context context) {
        super(context);
        mContext = context;

    }

    public CustomCheckBoxPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;

    }

    public CustomCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;

    }

    public CustomCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mContext = context;

    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
        TextView textView = (TextView) holder.findViewById(android.R.id.title);
        textView.setTextSize(14); // add your integer value is sp here
    }
}

И я добавляю это представление в макет предпочтений ( R.xml.preferences)

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <CustomCheckBoxPreference
        android:defaultValue="true"
        android:key="preferenceKey"
        android:persistent="true"
        android:title="title"/>


</PreferenceScreen>
person Garytech    schedule 08.03.2016

Ваше резюме занимает место для флажка.

Попробуйте добавить "‹ br />" после ограничений

или уменьшить размер шрифта

или вы можете явно установить ширину или высоту textView.

person JungJoo    schedule 14.09.2013