Tag Archives: Custom drawable

[Android] button uses the custom drawable file to set the background, and runs “error inflating class button”

(Android studio 3.1) when setting the background for the button control, the user-defined drawable file is used. No error is reported when running on Android 8.0, but an error is reported when running on Android 4.42. The error is as follows:

    

Finally, we find that when we switch to project mode, we can customize our own drawable file BT_ bg.xml The file is placed in the drawable-v24 folder, so BT_ bg.xml Move the file into the drawable folder (drawable-v24 can only be seen in project mode, but not in Android mode, as shown in the figure above). Run it again and the problem is solved.