android.view.InflateException: Binary XML file line #66: Error inflating class Button

created at 10-05-2021 views: 76

An error is reported when calling the pop-up window:

android.view.InflateException: Binary XML file line #66: Error inflating class Button
//popup
    public void authorlayout() {
        AlertDialog.Builder authorbuilder = new AlertDialog.Builder(MainActivity.this, R.style.authorDialog);///
        View author_layout = LayoutInflater.from(MainActivity.this).inflate(R.layout.author_layout, null);
        Button yes_author = author_layout.findViewById(R.id.yes_author);
        TextView textview_author = author_layout.findViewById(R.id.textview_author);
        textview_author.setText("    本《声明》包括:特别鸣谢和《软件协议》我们保留对本协议的最终解释权。");

        RelativeLayout author_TC = author_layout.findViewById(R.id.author_TC); //Get the view
//The object of the pop-up window width getLayoutParams() must have a parent layout or a null pointer
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) author_TC.getLayoutParams();
        params.width = getResources().getDisplayMetrics().widthPixels; //The width of the screen
//The height of the pop-up window
        params.height = getResources().getDisplayMetrics().heightPixels / 3 * 2; //2/3 of the height of the screen
        author_TC.setLayoutParams(params);//setting


        authorbuilder.setCancelable(false);
        AlertDialog alertDialog_author = authorbuilder.setView(author_layout).show();
        yes_author.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog_author.dismiss();
            }
        });
    }
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bg_alertdialog_alldelete"
    android:layout_gravity="start"
    android:paddingHorizontal="15dp"
    >
    <RelativeLayout
        android:id="@+id/author_TC"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:gravity="center"
        >
        <TextView
            android:id="@+id/textview_author_sm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="用户须知《声明》"
            android:textColor="@color/black"
            android:textSize="18dp"
            />
    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollview_author"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="55dp"
        android:layout_marginBottom="55dp"
        android:background="@drawable/bg_black_stroke"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/sc_layout"
            android:orientation="vertical"
            >
            <TextView
                android:id="@+id/textview_author"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="moli"
                android:textSize="15sp"
                android:textColor="#272727"
                />

        </LinearLayout>
    </ScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        >
        <Button
            android:id="@+id/yes_author"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@drawable/bg_buttonmain"
            android:layout_centerInParent="true"
            android:text="朕已阅"
            />
    </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

style

css style

The main error message:

   android.view.InflateException: Binary XML file line #66: Error inflating class Button
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at com.coder.ffmpeg.MainActivity.authorlayout(MainActivity.java:1414)
        at com.coder.ffmpeg.MainActivity$6.onNavigationItemSelected(MainActivity.java:524)
        at com.google.android.material.navigation.NavigationView$1.onMenuItemSelected(NavigationView.java:210)
        at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:840)
        at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
        at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:991)
        at com.google.android.material.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:416)
        at android.view.View.performClick(View.java:4780)

Found that the error occurred in the Button of the xml

<Button
            android:id="@+id/yes_author"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@drawable/bg_buttonmain"
            android:layout_centerInParent="true"
            android:text="朕已阅"
            />

After investigation, it is found that the background bg_buttonmain of setting the background is under drawable-v24. This is no problem in Android 7 and above, but an error will be reported under Android 7. The solution is to move it under the drawable

bg_buttonmain

created at:10-05-2021
edited at: 10-05-2021: