【发布时间】:2020-01-19 10:39:10
【问题描述】:
我决定将我的 Options 活动更新为 androidx.preference。所以我将implementation 'androidx.preference:preference-ktx:1.1.0' 添加到我的依赖项中。但是,现在我应用中其他地方的自定义复选框不再使用为它们提供的自定义按钮,而只使用默认复选框。(注意:这只发生在运行 Android 4.4 或更低版本的设备上)
删除 implementation 'androidx.preference:preference-ktx:1.1.0' 可解决此问题。有谁知道为什么会发生这种情况以及我如何克服它?
在活动布局中:
<androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/cbSharePosition"
style="@style/ActionCenter.Light.CheckBox"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:checked="true"/>
在 style_widgets.xml 中:
<style name="ActionCenter.Light.CheckBox" parent="android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/actioncenter_switch_button</item>
<item name="android:background">@color/transparent</item>
<item name="android:scaleType">centerInside</item>
<item name="android:adjustViewBounds">true</item>
</style>
actioncenter_switch_button.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/switch_on"
android:state_checked="true" />
<item android:drawable="@drawable/switch_off"
android:state_checked="false" />
<item android:drawable="@drawable/switch_on" />
</selector>
【问题讨论】:
-
也许preferences-ktx 中的一个扩展函数会影响你自己的东西。如果你使用标准的 java 依赖而没有 ktx 怎么办?
-
@Tenfour04 结果相同:(
标签: android user-interface gradle kotlin androidx