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

后端 未结 30 2417
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 13:48

I am receiving many errors of kind displayed in the subj. These errors seems to be occasional and I cannot reproduce them. From stack I can learn that such error may occurs

30条回答
  •  醉话见心
    2020-11-22 14:39

    We need to check API Version. I used to give background color to my LinearLayout like

    
    

    for sure I had the same error, as_royalblue.xml inside drawable folder

    
    
        
    
    

    and how I fixed it, actually it seems Api problem so we need to check the api level if it is above API 24 so we are able to use the way we like. But if it is under 24 we need to avoid usage, juts give a normal color or one color not color gradential mixed one.

    fun checkAPI_N(): Boolean {
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
                return true
            else
                return false
        }
    

    give id to your linearlayouts and set backgrounds if its ok

     if(UtilKotlin.checkAPI_N()){
                linlay_act_menu_container.setBackgroundResource(R.drawable.a_6)
                linlay_act_menu_logo.setBackgroundResource(R.drawable.as_strain)
            }else {//todo normal color background setting}
    

提交回复
热议问题