在按钮的android选择器中使用SVG [英] Using SVG in android selector for buttons

查看:36
本文介绍了在按钮的android选择器中使用SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 svg 作为 ImageView 的图标,它可以使用 app:srcCompat 给出但是当我想将它用于 Buttons 作为对于 api 低于 21 的设备,应用程序因找不到资源而崩溃的选择器

I am using svg for icons for ImageView it can be given using app:srcCompat But when i want to use it for Buttons as selector the app crashes with resource not found exception for devices with api below 21

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_enabled" android:state_enabled="true" />
    <item android:drawable="@drawable/button_disabled" android:state_enabled="false" />
</selector>

其中 button_enabled 和 button_disabled 都是 svg

Where button_enabled and button_disabled are both svg

推荐答案

我有自己的问题的答案.在您的活动中只需添加此静态块

I have the answer to my own question. In your activity just add this static block

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

这篇关于在按钮的android选择器中使用SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆