【发布时间】:2015-05-24 19:39:04
【问题描述】:
安卓新手。我正在实现一个导航抽屉,并在选择一个特定的按钮(抽屉中的位置 0)后开始一个活动。这些活动是在我导入的模块中定义的。
首先我创建了导航抽屉。我正在使用该位置来确定单击了哪个按钮。对于测试,我只使用一个按钮和一项活动。我将此项目作为模块导入: https://github.com/spacecowboy/NoNonsense-FilePicker
我希望能够从我的菜单开始他的第一个活动。我删除了他的清单的意图过滤器,以便我的应用程序首先在下面的代码中显示。问题是我的应用程序仍将首先启动导入的模块,而不是我的导航抽屉。如果我点击后退按钮,它会转到导航抽屉。由于我是菜鸟,所以无法发布屏幕截图。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fileexplorer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FileexplorerActivity"
android:label="@string/title_activity_fileexplorer">
<!--android:theme="@android:style/Theme.Holo"--> >
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<activity
android:name=".FileChooser"
android:label="Choose File" >
//android:theme="@android:style/Theme.Holo">
<action android:name="com.example.fileexplorer.FileChooser" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
</application>
</manifest>
我的 MainActivity 清单文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.jonny.nav" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:icon">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这就是我从抽屉代码开始活动的方式。
private void selectItem(int position) {
Intent selectedIntent = null;
switch(position){
case 0:
{
selectedIntent = new Intent(this.getActivity(), FileexplorerActivity.class);
startActivity(selectedIntent);
break;
}
default:
break;
}
}
【问题讨论】:
标签: android android-intent navigation drawer