简体   繁体   English

Android:使标签页启动新活动

[英]Android: Make tab launch new activity

I have a homescreen in my app that doesn't have any tabs. 我的应用程序中有一个主屏幕,没有任何标签。 It just has a series of buttons. 它只有一系列按钮。 Clicking a button launches the new activity that contains a tabbar at the top. 单击一个按钮将启动新活动,该活动顶部包含一个标签栏。 This functions normally. 此功能正常。 I can click through all the tabs just fine. 我可以点击所有选项卡。 What I'd like to do though is add another tab that doesn't really have content but instead, when clicked, will take the user back to the homescreen. 我想做的是添加另一个标签,该标签实际上没有内容,但是当单击时,会将用户带回主屏幕。 Is this possible, and if so how would I go about doing this? 这有可能吗,如果可以,我将如何去做?

What about just closing the "tabbar at the top"- Activity with finish() . 仅关闭“顶部的标签栏”-使用finish()活动呢? Your homescreen is right under if you did not finish() it. 如果您未finish()主屏幕,则主屏幕位于其正下方。 This is IMHO the most basic way to navigate in Android. 这是恕我直言,这是在Android中导航的最基本方法。

Another way is from your "tabbar at the top"- Activity you could do this 另一种方法是从“顶部的标签栏”-活动可以执行此操作

Intent intent = new Intent(this,homescreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

This should kill your "tabbar at the top"- Activity and start homescreen activity if it's not started. 这应该会杀死您的“顶部的标签栏”-活动,如果尚未开始,请启动主屏幕活动。 If it's started it will pop up 如果开始,它将弹出

Check this How do you use Intent.FLAG_ACTIVITY_CLEAR_TOP 检查此内容您如何使用Intent.FLAG_ACTIVITY_CLEAR_TOP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM