使Checkbox看起来像CheckboxPreference

时间:2018-07-07 04:51:50

标签: android android-checkbox preferencefragment

我希望能够在PreferenceFragment之外使用CheckboxPreference。

如何使我的复选框看起来像CheckboxPreferece?

主要我希望复选框位于右侧。我尝试将样式设置为@style/Preference.Checkbox。但这行不通。

<CheckBox
    android:id="@+id/map_shown"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="@dimen/spacing_extra_small"
    android:onCheckedChanged="@{ (switch, checked) -> event.setMapShown(checked) }"
    style="@style/Preference.CheckBoxPreference"
    android:text="@string/show_map" />

我需要这样看起来:

<android.support.v7.preference.CheckBoxPreference
    android:key="map_shown"
    android:title="Show Map"
    android:summaryOff="Map is shown"
    android:summaryOn="Map is not shown"
    android:defaultValue="false"/>

1 个答案:

答案 0 :(得分:0)

对于textview右侧的align复选框,然后尝试使用CheckedTextview

<CheckedTextView
        android:id="@+id/checkedTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="48dp"
        android:checkMark="?android:attr/listChoiceIndicatorMultiple"
        android:checked="true"
        android:text="CheckedTextView" />

enter image description here

希望它将对您有帮助!

相关问题