• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在按钮的android选择器使用SVG

用户头像
it1352
帮助1

问题说明

我正在使用 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

正确答案

#1

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

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

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfkege
系列文章
更多 icon
同类精品
更多 icon
继续加载