首页 > 解决方案 > android:autoMirrored 不适用于矢量可绘制对象

问题描述

当我的设备上设置了 RTL 语言时,为什么我的矢量可绘制对象拒绝镜像自身?我已经检查了为 RTL 布局启用自动镜像框,但由于某种原因这不起作用。

当前结果(英文)

在此处输入图像描述

预期结果(希伯来语)

在此处输入图像描述

当前结果(希伯来语)

在此处输入图像描述

可绘制的 XML

<vector
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:autoMirrored="true"
    android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
    <path
        android:fillColor="@android:color/white"
        android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
</vector>

活动布局

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val mTV = findViewById<TextView>(R.id.myTV)
        val appName = getString(R.string.app_name)
        val template = "$appName <img src=\"arrow\"/> $appName"
        mTV.text = Html.fromHtml(template, Html.FROM_HTML_MODE_COMPACT, imageGetter, null)
    }

    private val imageGetter = Html.ImageGetter { name ->
        val resId = if (name == "arrow") R.drawable.ic_arrow
        else throw IllegalArgumentException("what the heck is $name")

        ResourcesCompat.getDrawable(resources, resId, theme)?.apply {
            setBounds(0, 0, intrinsicWidth, intrinsicHeight)
        }
    }
}

标签: androidxmlandroid-drawableandroid-vectordrawable

解决方案


推荐阅读