一旦在 5.0+ 版本中运行我的应用程序,它就可以很好地工作。但对于较低版本,它会给我错误并且无法打开。
这是我收到的错误:
无法启动活动 ComponentInfo{lk.myoffers.app.myofferslk/lk.myoffers.app.myofferslk.MainActivity}:android.view.InflateException:二进制 XML 文件行 #17:错误膨胀类 android.support.design.widget.NavigationView
- 引起原因:android.view.InflateException:二进制 XML 文件第 17 行:错误膨胀类 android.support.design.widget.NavigationView
- 引起原因:java.lang.reflect.InitationTargetException
- 引起原因:android.content.res.Resources$NotFoundException:资源 ID #0x7f020052
- 在 lk.myoffers.app.myofferslk.MainActivity.onCreate(MainActivity.java:84)
我已经尝试了 Stack Overflow 上的所有方法,但问题仍然存在。
我是 Android 新手,请问问题出在哪里?
setContentView(R.layout.activity_main);
位于第 84 行。
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener{
public static int pageCount = 1;
private int totalLoadedCount;
private AdListAdapter adapter;
TextView txtUserName;
Button btnReconnect;
private static String LIST_INSTANCE_STATE = "items";
private ArrayList<AdList> adLists = new ArrayList<AdList>();
private ArrayList<MasterCategory> mstCategory = new ArrayList<MasterCategory>();
private MasterCategoryAdapter catAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
totalLoadedCount = 0;
My 活动主线:
<?xml version="1.0" encoding="utf-8"?>
<include
layout="@layout/app_bar_main"
android:id="@+id/aa"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"
/>
My Android 清单 file:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme1"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
对于 style.xml 我有以下代码行
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:button">@color/colorButton</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
</style>
<style name="MIP_theme" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
我已经尝试了所有方法,但它无法在低于 5 的 Android 上运行
Gradle 版本集
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
The 最低版本 is 23.
这是我的 build.gradle
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "lk.myoffers.app.myofferslk"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.github.darsh2:MultipleImageSelect:v0.0.4'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
}