当前位置: 首页 > 知识库问答 >
问题:

Android应用程序崩溃,而在API 19上呈现vector asset在API 20以上的情况下工作良好

白泽语
2023-03-14

矢量资产:ic_warning_white_24px.xml

activity_my.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp"
    tools:context="MyActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/inputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Hint" />

        </android.support.design.widget.TextInputLayout>

        <android.support.v7.widget.AppCompatButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:drawableEnd="@drawable/ic_warning_white_24px"
            android:drawableRight="@drawable/ic_warning_white_24px"
            android:gravity="start|center_vertical"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:text="Button"
            android:textColor="@color/white" />

    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

myActivity.java

public class MyActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
    }
}
defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

我也尝试了一些事情

static
{
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

.

public class MyActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
    }
}

共有1个答案

颛孙钱青
2023-03-14

不能对drawableLeft,drawableLight使用矢量绘图。对不起。

也试试

        app:drawableEnd="@drawable/ic_warning_white_24px"
        app:drawableRight="@drawable/ic_warning_white_24px"

而不是

        android:drawableEnd="@drawable/ic_warning_white_24px"
        android:drawableRight="@drawable/ic_warning_white_24px"
 类似资料: