5

こんにちは、私は好みとしてメッセージ設定に取り組んでいます。

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>

および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"/>

これを使用すると、下のスクリーンショットのように文字サイズが大きくなります。しかし、チェックボックスが表示されません。これを解決するにはどうすればよいですか?

ここに画像の説明を入力

4

4 に答える 4

8

ここでの答えのほとんどは、完全に間違っているか、同じことを行う簡単な方法がある場合に実装するには複雑すぎます。

将来の読者のために - を変更でき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>

wheretextColorPrimaryは checkBoxPreference のタイトルの色をtextColorSecondary変更し、概要の色を変更します。

于 2014-04-16T10:08:39.490 に答える
0

次のように、カスタム レイアウトにチェックボックスを追加する必要があります。

<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" />
于 2013-12-13T20:25:24.587 に答える
0

チェックボックスの設定でテキストのサイズを大きくするために、カスタム クラスを使用しました。

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>
于 2016-03-08T13:33:06.400 に答える
-1

概要がチェックボックスのスペースを占めています。

制限の後に「< br />」を追加してみてください

またはフォントサイズを小さくする

または、textView の幅または高さを明示的に設定できます。

于 2013-09-14T04:18:47.640 に答える