Android 每个活动的选项卡栏

Android 每个活动的选项卡栏,android,android-tabactivity,Android,Android Tabactivity,我有一个显示5个选项卡的选项卡栏。我希望选项卡栏显示在我应用程序中的每个活动上。选项卡栏显示的唯一活动是选项卡中的5个活动。我使用的是TabActivity,我知道它已经被弃用了,但是除了这5个活动之外,还有什么方法可以让它在任何地方都工作吗?我需要一个相当快的解决方案,这不会对我的其他代码产生太大的影响 下面是选项卡栏活动 package com.appname; import android.app.TabActivity; import android.content.Intent; i

我有一个显示5个选项卡的选项卡栏。我希望选项卡栏显示在我应用程序中的每个活动上。选项卡栏显示的唯一活动是选项卡中的5个活动。我使用的是TabActivity,我知道它已经被弃用了,但是除了这5个活动之外,还有什么方法可以让它在任何地方都工作吗?我需要一个相当快的解决方案,这不会对我的其他代码产生太大的影响

下面是选项卡栏活动

package com.appname;

import android.app.TabActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;

import com.readystatesoftware.viewbadger.BadgeView;

@SuppressWarnings("deprecation")
public class TabController extends TabActivity {  
   /** Called when the activity is first created. */ 
   TabHost tabHost; 
   SharedPreferences prefs;
   public static BadgeView badgeTab;
       @Override  
       public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);    

            tabHost = getTabHost();
            TabHost.TabSpec spec;  
            Intent intent;              

        intent = new Intent().setClass(this, Item1.class);  
        spec = tabHost.newTabSpec("Item 1").setIndicator("Item 1",  getResources().getDrawable(R.drawable.item1))  
                  .setContent(intent); 
        tabHost.addTab(spec);               

        intent = new Intent().setClass(this, Item2.class);  
        spec = tabHost.newTabSpec("Item 2").setIndicator("Item 2", getResources().getDrawable(R.drawable.item2))  
                  .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Item3.class);  
        spec = tabHost.newTabSpec("Item 3").setIndicator("Item 3", getResources().getDrawable(R.drawable.item3))  
                  .setContent(intent);     
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Item4.class);  
        spec = tabHost.newTabSpec("Item 4").setIndicator("Item 4", getResources().getDrawable(R.drawable.item4))  
                  .setContent(intent);              
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Item5.class);  
        spec = tabHost.newTabSpec("Item 5").setIndicator("Item 5", getResources().getDrawable(R.drawable.item5))  
                  .setContent(intent);      
        tabHost.addTab(spec);                  

        //Set background images
       for(int i=0;i<tabHost.getTabWidget().getChildCount();i++){                      

        tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tabbackground); //unselected
       }
       tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.selectedtab); // selected

        tabHost.setOnTabChangedListener(new OnTabChangeListener(){
        public void onTabChanged(String tabId) {
            for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
            {
                tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tabbackground); //unselected
            }
            tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.selectedtab); // selected
        }
    });

    TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);               
    badgeTab = new BadgeView(this, tabs, 2);
    badgeTab.setBadgePosition(2);
    if(NotificationService.messageCount <= 0){
        badgeTab.hide();
    }
    else{                                                                                                               
        badgeTab.setText(String.valueOf(NotificationService.messageCount));
        badgeTab.show();
    }

    Intent tabIntent = this.getIntent();
    if (tabIntent != null && tabIntent.getExtras() != null) {
        if(tabIntent.getExtras().containsKey("ID_KEY")){
            int id_Key = this.getIntent().getExtras().getInt("ID_KEY");

            if (id_Key > 0) {
                tabHost.setCurrentTab(2);
            }
        }
    }           

}

}

您可以制作一个带有5个“五”按钮的自定义线性布局,并控制单击事件。如果您愿意,我可以发布代码。如果您可以发布代码,那就太好了。但这难道不意味着按钮看起来不像标签栏吗?