Android 增加CheckboxPreference标题和摘要文本大小,并使首选项发光

Android 增加CheckboxPreference标题和摘要文本大小,并使首选项发光,android,android-preferences,listpreference,checkboxpreference,Android,Android Preferences,Listpreference,Checkboxpreference,嗨,我正在优先处理邮件设置 我正在尝试更改CheckboxPreference的android:title和android:summary文本字体大小 为此,我正在尝试下面的代码 <PreferenceCategory android:key="prefcategory1" android:title="GENERAL SETTINGS..." > <CheckBoxPreference android:defaultValue

嗨,我正在优先处理邮件设置

我正在尝试更改CheckboxPreference的android:title和android:summary文本字体大小

为此,我正在尝试下面的代码

   <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>


您的摘要占用了复选框的空间

尝试在限制后添加“

或者减小字体大小


或者,您可以显式设置文本视图的宽度或高度。

您需要将复选框添加到自定义布局中,如下所示:

<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" />

这里的大多数答案都是完全错误的,或者太复杂,无法实现,因为有更简单的方法可以实现

仅供未来读者使用-您可以在
style.xml
中更改
textSize/textColor

   <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>

34便士
#000000
#000000

其中
textColorPrimary
将更改复选框首选项标题的颜色,
textColorSecondary
将更改摘要的颜色

为了增加checkboxpreference中文本的大小,我使用了一个自定义类

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)中


这不仅仅改变了首选项屏幕上的文本
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
    }
}
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

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


</PreferenceScreen>