Android 主页按钮结束actionbar中的应用程序
我需要一些帮助,在我的应用程序中,我有第一个活动(主),然后我调用一个新的活动(带有片段、选项卡、滑动),现在我想启用左上角的home按钮。它可以工作,但它会结束我的应用程序,然后回到我的“手机屏幕” 这是我的舱单Android 主页按钮结束actionbar中的应用程序,android,Android,我需要一些帮助,在我的应用程序中,我有第一个活动(主),然后我调用一个新的活动(带有片段、选项卡、滑动),现在我想启用左上角的home按钮。它可以工作,但它会结束我的应用程序,然后回到我的“手机屏幕” 这是我的舱单 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="overskov.rhk
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="overskov.rhkbrand"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="overskov.rhkbrand.MainActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="overskov.rhkbrand.Under_menu"
android:label="@string/title_activity_under_menu"
android:parentActivityName="overskov.rhkbrand.MainActivity"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="overskov.rhkbrand.MainActivity" />
</activity>
<activity
android:name="overskov.rhkbrand.Etage_menu"
android:label="@string/title_activity_etage_menu" >
</activity>
</application>
</manifest>
据安卓开发者称:
一旦在清单中像这样指定了父活动,并且使用setDisplayHomeAsUpEnabled()启用了Up按钮,您的工作就完成了,操作栏将正确地向上导航
那么我做错了什么
谢谢
丹尼斯
}覆盖主页按钮怎么样
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
我试过了,现在又试了一次,但没用,它仍然会终止应用程序。你试过从清单中删除android:parentActivityName和meta标记吗?只需使用单向OOPS!在名为?OMG!的setActivityForResult(SecondActivity)之后,您是否完成了第一个活动!你不能完成你的第一项活动,因为你必须回来。删除finish()。并使用startActivityForResult()而不是startActivity()
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1 = (Button) findViewById(R.id.save);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Under_menu.class));
finish();
}
});
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Etage_menu.class));
finish();
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}