嗨,我创建了示例项目但崩溃了。
我用 kitkat 运行设备,但我的应用程序崩溃并且只显示异常错误的消息,为什么?我使用 android studio lastversione
我的 build.grade添加支持 22 和 appcompat
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.android.xxx"
minSdkVersion 19
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
//compile 'com.android.support:appcompat-v7:22.0.0'
//compile 'com.github.shell-software:fab:1.0.5'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'com.android.support:recyclerview-v7:22.0.0'
compile 'com.android.support:design:22.2.0'
compile 'com.google.code.gson:gson:2.3'
}
我的测试活动是从 android studio 创建的空白活动
我的测试活动
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 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"
tools:context="com.android.xxx.TestActivity">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_drawer"
android:layout_gravity="bottom|end" />
</RelativeLayout>
更新
我找到了最佳配置
这在设备和模拟器上编译并运行,我的布局
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
>
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar"
/>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="401dp">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_black"
android:layout_gravity="start|left" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:menu="@menu/drawer"
/>
</android.support.v4.widget.DrawerLayout>
我的脚本
apply plugin: 'com.android.application'
android {
// compileSdkVersion 22
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.android4dev.navigationview"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile 'com.android.support:appcompat-v7:22.2.0'
// compile 'com.android.support:design:22.2.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}