如何在选择器中使用svgs进行预棒棒糖版本? [英] How to use svgs in selector for pre lollipop version?
问题描述
我在选择器上使用了选择器,但它在棒棒糖之前的版本中会出现问题
I used selector for checkbox it works, but it causes problems for pre lollipop version
<selector xmlns:android="...">
<item android:state_checked="true"
android:drawable="@drawable/checked_icon" />
<item android:drawable="@drawable/icon" />
</selector>
<CheckBox
android:button="@drawable/terms_checkbox"/>
它导致resourcNotFoundexception,如何解决该问题,有什么解决方法吗?
it causes resourcNotFoundexception, How to solve the problem, is there any solution?
致命异常:主要 android.view.InflateException:二进制XML文件第70行:膨胀类CheckBox时出错
FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #70: Error inflating class CheckBox
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/terms_service1.xml from drawable resource ID #0x7f020121
at android.content.res.Resources.loadDrawable(Resources.java:2096)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.CompoundButton.<init>(CompoundButton.java:74)
at android.widget.CheckBox.<init>(CheckBox.java:68)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Draw
推荐答案
1)在您的build.gradle
中:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
2)在您的应用程序类中:
2) In your Application class:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
3)使用由android:button插入的app:buttonCompat作为CheckBox 或由Android插入的buttonCompat:在style.xml中按入您的按钮
3) Use app:buttonCompat insted of android:button for CheckBox or buttonCompat insted of android:button your in style.xml
4)就我而言,我需要添加
4) In my case I needed to add
android:focusable="true"
android:clickable="true"
我的CheckBox中用于onClick反应的参数.
parameters in my CheckBox for onClick reaction.
5)就我而言,我需要使用
androidx.appcompat.widget.AppCompatCheckBox
而不是xml布局中的CheckBox
.
5) And in my case I needed to use
androidx.appcompat.widget.AppCompatCheckBox
instead of CheckBox
in xml layout.
文章是有帮助的.
这篇关于如何在选择器中使用svgs进行预棒棒糖版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!