android - android:button drawable for radiobutton未在模拟器中加载
问题描述
我想创建自定义 RadioButtons 但我遇到了问题。当我在 Android Studio 中预览我的工作时,一切似乎都很好,但在模拟器中我的可绘制对象没有正确加载。我错过了什么/做错了什么?我的代码如下所示:
XML RadioGroup:
`<RadioGroup
android:id="@+id/ec_radiogroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="10dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ic_ec_switch">
<RadioButton
style="@style/ec_radiobuttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/it_radiobutton_sunrise"
android:padding="16dp"
android:text="Morgen" />
<RadioButton
style="@style/ec_radiobuttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/it_radiobutton_sun"
android:padding="16dp"
android:text="Mittag" />
<RadioButton
style="@style/ec_radiobuttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@drawable/it_radiobutton_sunrise"
android:padding="16dp"
android:text="Abend" />
</RadioGroup>`
XML 可绘制(android:button="@drawable/it_radiobutton_sunrise"):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="@drawable/ic_radiobutton_sunrise_active"/>
<item
android:state_checkable="true"
android:drawable="@drawable/ic_radiobutton_sunrise_active"/>
<item
android:state_focused="true"
android:drawable="@drawable/ic_radiobutton_sunrise_active"/>
<item
android:state_activated="true"
android:drawable="@drawable/ic_radiobutton_sunrise_active"/>
<item
android:state_pressed="true"
android:drawable="@drawable/ic_radiobutton_sunrise_active"/>
<item
android:state_selected="true"
android:drawable="@drawable/ic_radiobutton_sunrise_active"/>
<item
android:state_checked="false"
android:drawable="@drawable/ic_radiobutton_sunrise_inactive" />
<item
android:state_checkable="false"
android:drawable="@drawable/ic_radiobutton_sunrise_inactive" />
<item
android:state_focused="false"
android:drawable="@drawable/ic_radiobutton_sunrise_inactive" />
<item
android:state_activated="false"
android:drawable="@drawable/ic_radiobutton_sunrise_inactive" />
<item
android:state_pressed="false"
android:drawable="@drawable/ic_radiobutton_sunrise_inactive" />
<item
android:state_selected="false"
android:drawable="@drawable/ic_radiobutton_sunrise_inactive" />
</selector>
解决方案
我在一些较旧的 android 版本上遇到了类似的问题,请尝试将其添加到模块 build.gradle 。
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}}
推荐阅读
- javascript - 更改标准 pwa 安装通知
- deep-learning - 如何将我的 Pytorch 模块(使用就地操作)更改为可区分的?
- python - 使用一些停用词来过滤另一个路径列表
- javascript - 过滤器在 Vue.js 中不起作用。我该如何解决?
- html - css卡片翻转动画翻转然后内容闪烁可见
- azure - Azure 策略:删除资源组上的锁定
- google-cloud-platform - GCP Datafusion 重复来自 GCS 的相同数据
- vue.js - Vue TypeError:“无法读取未定义的属性'Bd'”
- python - 有没有办法在 python 中压缩列表/元组的内部元素?
- sql - 如何拒绝手动插入表格?