我在使用API 22的设备上开发应用程序,但是当我尝试使用API 19(Xiomi设备)在设备上安装相同的应用程序时,我收到以下错误;
android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.widget.Toolbar
这是activity_login.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".LoginActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_login" />
</android.support.design.widget.CoordinatorLayout>
这是content_login.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_login" tools:context=".LoginActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="username"
android:ems="10"
android:id="@+id/etUsername"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="password"
android:ems="10"
android:id="@+id/etPassword"
android:layout_below="@+id/etUsername" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Mobile Number"
android:ems="10"
android:id="@+id/etMobile"
android:layout_below="@+id/etPassword" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/bLogin"
android:layout_marginTop="40dp"
android:layout_below="@+id/etPassword"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/etPassword" />
</RelativeLayout>
这是build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.test.myschool"
minSdkVersion 17
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.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
这是错误日志:
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: FATAL EXCEPTION: main
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: Process: com.test.myschool, PID: 5253
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.myschool/com.test.myschool.LoginActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.v7.widget.Toolbar
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2382)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2434)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:154)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:110)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.os.Looper.loop(Looper.java:193)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5349)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:835)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
03-14 18:55:06.162 5253-5253/com.test.myschool E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)