简体   繁体   English

自定义标题栏和选项卡

[英]Custom Titlebar AND Tabs

我知道这是不可能的,但是有没有解决方法,因此我可以同时使用选项卡和自定义标题栏,而不必在每个单独的活动中都要求标题栏?

You can create a Custom title bar for your TabActivity. 您可以为TabActivity创建一个自定义标题栏。 so that both Tabs will be there and Custom Title bar, and further you can refer to the title bar from any activity with in the tabs by using the context of TabActivity. 这样,两个选项卡都将出现在此处,并且有“自定义标题”栏,并且进一步,您可以使用TabActivity的上下文在选项卡中使用任何活动引用标题栏。

Check this link for the tutorial of creating custom title bar for any activity http://www.helloandroid.com/tutorials/how-create-custom-titlebar 在此链接中查看有关为任何活动创建自定义标题栏的教程http://www.helloandroid.com/tutorials/how-create-custom-titlebar

so using this tutorial you can create custom-titlebar for your TabActivity 因此,使用本教程,您可以为TabActivity创建自定义标题栏

hope it helps... 希望能帮助到你...

Update for comment 更新评论

you can add a method like this in you tab activity for updating the Title. 您可以在标签活动中添加这样的方法来更新标题。 use your own custom layout for title. 使用您自己的自定义布局标题。 update the fields in the method. 更新方法中的字段。

here for example im using one layout with one TextView 例如,我在这里使用一种布局和一个TextView

 public void setMyTitle(String str)
{
    MainTab.mTab.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_title);
    TextView title=(TextView) findViewById(R.id.titleText);
    title.setText(str);
}

and in Your TabActivity class 并在您的TabActivity类中

static MainTab mTab;//initialize the context of TabActivity from on create method

in onCreate() of TabActivity class 在TabActivity类的onCreate()中

mTab=this; 

and from any activity with in the Tab you can set the title like this. 并可以通过“标签”中的任何活动设置标题。

 MainTab.mTab.setMyTitle("MyTitle is ");

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

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