Android:如何在选项卡内容中打开新活动,而不是全屏?
我的 Android 应用程序是使用选项卡栏创建的,根 Activity 扩展了 TabActivity。我遇到的问题是我总是希望标签栏可见。
假设其中一个选项卡中的活动之一有一个按钮,当我点击该按钮时,我想使用以下代码打开一个新活动:
Intent intent = new Intent(this, MyActivity.class);
startActivity(intent);
新活动在选项卡栏上全屏打开。我希望它显示在具有选项卡内容的 FrameLayout 中,以便选项卡栏仍然可见。我想使用一个活动,以便我可以使用返回堆栈等。这在使用选项卡栏的应用程序中必须是标准的,那么我在这里做错了什么?
My Android app is created with a tab bar and the root activity is extending TabActivity. The problem I have is that I always want the tab bar to be visible.
Lets say that one of the activitys in one of the tabs have a button and when I tap that button I want to open up a new activity with the following code:
Intent intent = new Intent(this, MyActivity.class);
startActivity(intent);
The new activity opens up in full screen over the tab bar. I want it to show up in the FrameLayout where I have the tab content so that the tab bar is still visible. I want to use an activity so that I can use back stack etc. This must be standard in an app using a tab bar, so what am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定,但我认为如果您希望活动在选项卡内容中显示,您应该声明一个 tabspec,就像常规选项卡一样,或者直接将 TabHost 当前选项卡设置为您想要显示的选项卡/活动?
I'm not sure but i think that if you want the activity to display within the tab content you should declare a tabspec, like for regular tabs, or directly set the TabHost current tab to the tab/activity you want to display?
要创建选项卡式布局,您应该使用
TabHost
和TabWidget
,如下所述 此处。To create a tabbed layout you should use a
TabHost
and aTabWidget
as described here.似乎就像克里斯蒂安所说,没有好的方法可以做到这一点
我从那篇文章中了解到有一种方法,但它是一种“黑客”,而且 Android 并不是为了使用这种 UI 理念而构建的。
不过,我对此有一些疑问:
因此,如果我的应用程序分为五个不同的大部分,则非常适合划分为选项卡(就像我在 iPhone 上所做的那样)。如果没有标签栏,你会如何在 Android 中以良好的方式解决这个 UI 问题?或者我应该使用标签栏但全屏打开新活动?
Seems like it is like Cristian says, there is no good way of doing this
From what I understand from that post there is a way but it is a "hack" and that Android isn't built to use this idea of an UI.
I have some questions about this, though:
So if my app is divided into five different large parts, that is perfect to divide into tabs (like I do on the iPhone). How would you solve this UI in Android in a good way without a tab bar? Or should I use a tab bar but open up new activitys full screen?