Tag Archives: drawable

[Android] ImageView setting background image error: error inflating class ImageView

(Android studio 3.1) the ImageView control is used in the layout file, and Src refers to the vector asset file created by itself. When running on Android 4.42, an error is reported as follows:

I used it on Android 8.0 mobile phone before, but it didn’t appear this problem. When I ran it on Android 4.42, I made a mistake. The first time I met this problem, I didn’t know what was wrong. Later, when I solved another problem, I suddenly realized that this problem might come from:

      

   

In the development process, I’m used to Android mode, and there are only a few folders in the res directory. Switch to project mode. In addition to the drawable folder, there is also the drawable-v24 folder in the res directory. I found that the vector asset file I created was actually placed in drawable-v24. Maybe that’s the problem. So I moved the vector asset file from the drawable-24 folder to the drawable directory, and then there was no running error.

Later, I went to the blog to search for information and found that Google only provided vector support when Android 5.0 was released. No wonder there was no error when I created the vector asset file to run in the drawable folder in Android 8.0. Maybe it was because vector was relatively mature in higher versions. Finally, a blog about vector written by Dashen is attached https://blog.csdn.net/eclipsexys/article/details/51838119 , I feel that I have learned a lot, which is convenient for further inquiry in the future.

 

[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.