如何为 Android 的 TabActivity 设置一个自定义标题

华宰 发布于 2011/07/11 07:31
阅读 3K+
收藏 0

我想为我的 TabActivity 设置一个自定义标题,下面的代码不行,有什么问题吗,请大家帮我看看:

public class ShowExam_TabAct extends TabActivity {
public static boolean customTitleSupported = false;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabs);

    customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    if (customTitleSupported) {
         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                    R.layout.title);
        TextView title = (TextView) findViewById(R.id.TV_title);
        title.setText("new title!");
    }

    TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);

    tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Mars")
            .setContent(new Intent(this, List1.class)));
    tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Earth")
            .setContent(new Intent(this, List2.class)));

}
}
加载中
0
blur
blur

TabHost tabHost = getTabHost();

试试这个。我也记不太清了。

返回顶部
顶部