如何暂时删除 TabHost 的 Tabwidget?

发布于 2024-12-17 12:30:05 字数 297 浏览 2 评论 0原文

我正在开发一个使用 TabHost 的应用程序。在我的 TabHost 中,有四个选项卡。每个选项卡都有自己的 ActivityGroup。现在,我想要的是,在选项卡下的 ActivityGroup 内的 Acitivty 中,我想暂时删除 Tabwidget,以便框架布局在设备的整个屏幕上可见。然后,当该 Activity 切换到另一个 Activity 时,Tabwidget 将重新出现在屏幕上。所以第一个问题是,我可以这样做吗?如果那样的话,我该怎么办?如果不可能,那么是否可以在 Tabwidget 选项卡下的正常活动和 ActivityGroup 内的活动之间切换?

I am developing an app where i used TabHost. Inside my TabHost, there are four tabs. Each tab has its own ActivityGroup. Now, what i want is, in a Acitivty inside one of my ActivityGroup under a tab, i want to remove the Tabwidget temporarily so that the frameLayout will be visible through entire screen of the device. Then, when the activity switch to another activity, the Tabwidget will re-appear on the screen. So the first question is, can i do this? If then, how can i do that? If not possible, then is it possible to switch between a normal activity and an activity inside ActivityGroup under a tab of Tabwidget?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃不饱 2024-12-24 12:30:05

StartActivity() 也在 ActivityGroup 内部工作。
因此 Activity 将在全屏中启动,并且 finish(); 将发送回 ActivityGroup()

StartActivity() works inside ActivityGroup also .
so activity will start in complete screen and finish(); will send back to ActivityGroup() .

云朵有点甜 2024-12-24 12:30:05

对于底部的选项卡:

public void hideTab()
{
    TabWidget tabwidget=getTabWidget();
    RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)tabwidget.getLayoutParams();
    params.setMargins(0, 0, 0, -100);

}
public void showTab()
{
    TabWidget tabwidget=getTabWidget();
    RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)tabwidget.getLayoutParams();
    params.setMargins(0, 0, 0, -3);

}

For tab at the bottom:

public void hideTab()
{
    TabWidget tabwidget=getTabWidget();
    RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)tabwidget.getLayoutParams();
    params.setMargins(0, 0, 0, -100);

}
public void showTab()
{
    TabWidget tabwidget=getTabWidget();
    RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)tabwidget.getLayoutParams();
    params.setMargins(0, 0, 0, -3);

}
甩你一脸翔 2024-12-24 12:30:05

由于 TabWigetView 的子类,您应该能够使用 setVisibility() 隐藏/重新显示它。

您需要对 TabWidget 的引用 - 该引用需要在哪里,取决于哪个类将处理隐藏/显示。在下面的示例中,我假设您将功能放入 TabActivity 中 - 因此我们添加两个方法和对 TabWidget 的引用:

TabWidget myTabWidget; //You will need to find it in the layout in onCreate using findViewById( R.id.idOfYourTabWidget ).

public void hideTabs() {
  myTabWidget.setVisibility( View.GONE );
}

public void showTabs() {
  myTabWidget.setVisibility( View.VISIBLE );
}

然后在 Activity< /code> 需要隐藏选项卡,您需要执行以下操作:

Activity activity = getParent(); //Might be getParent().getParent(); if you're inside an ActivityGroup.
if( activity instanceof MyTabActivity ) //Just to make sure.
  ((MyTabActivity) activity).hideTabs();

要重新显示选项卡,执行相同的操作,但改为调用 ((MyTabActivity) Activity).showTabs();

Since TabWiget is a subclass of View you should be able to hide/reshow it using setVisibility().

You would need a reference to your TabWidget - where this reference needs to be, depends on what class will handle hide/show. In my example below I will assume you put the functionality in your TabActivity - so there we add two methods and a reference to the TabWidget:

TabWidget myTabWidget; //You will need to find it in the layout in onCreate using findViewById( R.id.idOfYourTabWidget ).

public void hideTabs() {
  myTabWidget.setVisibility( View.GONE );
}

public void showTabs() {
  myTabWidget.setVisibility( View.VISIBLE );
}

Then in the Activity that needs to hide the tabs you will need to do something like:

Activity activity = getParent(); //Might be getParent().getParent(); if you're inside an ActivityGroup.
if( activity instanceof MyTabActivity ) //Just to make sure.
  ((MyTabActivity) activity).hideTabs();

And to reshow the tabs, the same thing but calling ((MyTabActivity) activity).showTabs(); instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文