背景形状在Android的API级别16中无法完美运行

vin*_*mar 2 xml android

我设计了一种形状来应用于线性布局的背景。它在API级别21上可以完美运行,但在API级别16上却无法正常工作,请帮助我。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">
    <stroke
       android:drawable="@android:id/background"
       android:width="3dp"
       android:color="#023e64">
    </stroke>

    <corners
        android:bottomLeftRadius="16dp"
        android:bottomRightRadius="16dp"
        android:topLeftRadius="16dp"
        android:topRightRadius="16dp"/>

</shape>
Run Code Online (Sandbox Code Playgroud)

R. *_*ski 6

这是一个已知的错误,在API 16上,可绘制背景变成黑色。

只需将背景设置为android.color.R.transparent

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <stroke
        android:drawable="@android:id/background"
        android:width="3dp"
        android:color="#023e64">
    </stroke>
    <solid android:color="@android:color/transparent"/>


    <corners
        android:bottomLeftRadius="16dp"
        android:bottomRightRadius="16dp"
        android:topLeftRadius="16dp"
        android:topRightRadius="16dp"/>

</shape>
Run Code Online (Sandbox Code Playgroud)