【问题标题】:Make Checkbox look like CheckboxPreference使 Checkbox 看起来像 CheckboxPreference
【发布时间】:2018-07-07 04:51:50
【问题描述】:

我希望能够在 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"/>

【问题讨论】:

  • 分享你的代码。
  • @HemantParmar 我认为代码应该无关紧要,但我已经分享了代码
  • 你必须扩展复选框以设置自定义属性。

标签: android android-checkbox preferencefragment


【解决方案1】:

要将复选框右侧对齐到textview,然后尝试使用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" />

希望对你有帮助!!

【讨论】:

  • 您的代码只会改变背景。我不想改变背景。我只希望我的复选框看起来像一个 PreferenceCheckbox(右侧有复选框),即在设置中找到的那个。另外,没有扩展复选框就没有办法(比如使用样式)?
  • 右边有复选框??你能解释一下吗?
  • 您一定见过应用程序中的设置活动(PreferenceFragment 或 PreferenceActivity)。 PreferenceCheckbox 右侧有复选框,左侧有文本。而普通的 Checkbox 小部件的复选框位于左侧,文本位于右侧。
  • ohk 表示你想要右侧的复选框和左侧的文本??
  • 是的,还有一个总结,如果可能的话,以一种简洁的方式,而不必扩展基类。
猜你喜欢
  • 2011-04-27
  • 2013-12-09
  • 2015-06-23
  • 2014-11-05
  • 2016-06-18
  • 2013-02-03
  • 2011-11-22
  • 2021-11-28
  • 1970-01-01
相关资源
最近更新 更多