Increasing CheckboxPreference title and summary text size and glowing of an preference entry
Asked Answered
L

4

5

Hi I am working on Message Settings as a preference.

I am trying to change android:title and android:summary text font size of CheckboxPreference.

enter image description here

For this I am trying out the below code

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

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

By using this, the text size is increased as in below screen shot.But, I am not able to see the checkbox..How do I resolve this?

enter image description here

Lipread answered 13/9, 2013 at 13:24 Comment(0)
I
8

Most of the answers here are outright wrong or too complex to implement when there are simpler ways to do the same.

Just for future readers - You can change the textSize/ textColor in your 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>

where textColorPrimary will change the color of title of checkBoxPreference and textColorSecondary will change the color of summary.

Iceberg answered 16/4, 2014 at 10:8 Comment(1)
This changes more than only the text from the preferencescreenPollinosis
A
0

You need to add the checkbox to your custom layout like so:

<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" />
Apivorous answered 13/12, 2013 at 20:25 Comment(0)
B
0

In order to increase the size of the text in a checkboxpreference, i used a custom class.

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

And I add this view in the preference layout ( 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>
Bigname answered 8/3, 2016 at 13:33 Comment(0)
P
-1

Your summary is taking up the space for the checkbox.

Try adding "< br />" after limits

or reduce the font size

or you can explicitly set the width or height of the textView.

Pigeon answered 14/9, 2013 at 4:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.