使用MultipleTheme设置夜间模式跳转时报InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class异常
xml的代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/main_bg" >仔细看也没错误 可为什么一直报错呢?把backgroudn设置成其他颜色比如
android:background="@color/white"就不报错了。
这时候应该想到这个activity是否在onCreate设置了夜间模式的Theme
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*夜间模式*/ if(SharedPreferencesMgr.getInt("theme", 0) == 1) { setTheme(R.style.theme_2); } else { setTheme(R.style.theme_1); } }这样就ok了 问题解决