gpt4 book ai didi

android - 操作返回(向上导航)到自定义 Activity 的操作栏?

转载 作者:行者123 更新时间:2023-11-30 01:38:10 24 4
gpt4 key购买 nike

我的应用程序中有很多 Activity

因为我已经给了这个

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

从其他 Activity 返回主页

喜欢下面

enter image description here

如果我按下这三个按钮,所有菜单都可以使用这是我的选项菜单

@覆盖public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();

if (id == R.id.abc) {
Intent mypIntent = new Intent(this, abc.class);
startActivity(mypIntent);
return true;
}

else if (id == R.id.web) {
Intent webIntent = new Intent(this, Web.class);
startActivity(webIntent);
return true;
}
else if (id == R.id.about) {
Intent aboutIntent = new Intent(this, About.class);
startActivity(aboutIntent);
return true;
}
.
.
.
..

return super.onOptionsItemSelected(item);
}

这里没有名为 id == R.id.loginid == R.id.home 的菜单,但它要登录几天前就不见了回家 Activity

但是如果我按返回.. 返回操作会重定向到登录页面 Inst-ed of Home

我已经使用共享首选项为我的应用程序添加了一个登录页面..现在是启动器 Activity ..

在我的登录 Activity 中,如果用户登录后,它应该每次都重定向到主页 Activity 。并且工作正常..

但是在操作栏上,当我按下箭头按钮时,它会重定向到空的登录页面。如果我按下取消整个应用程序正在运行..我的凭据是安全的,除了这个操作栏..

更新

我也有 Given Intent 如果登录凭据成功重定向到应用程序启动时的主页 Activity ,它将每次检查

一切都很好,除了行动回来

如何解决这个问题...

最佳答案

好的,请确保您按以下方式声明 Activity -

<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- The meta-data element is needed for versions lower than 4.1 -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>

现在在每个 Activity 中添加以下代码块-

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

更新添加一个新的类文件来检查登录或不使用 home 作为默认.. 并将你的新类替换为 Manifest

中的 launcher

关于android - 操作返回(向上导航)到自定义 Activity 的操作栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34869198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com