如何在 TabActivity 中显示 ActionBar?

How to show ActionBar in TabActivity?

我创建了一个带有两个选项卡的 TabActivity。它们的内容是两个独立的活动。一切正常。但我想在 TabActivity 之上显示 ActionBar。 我的截图是

请任何人告诉如何在我的 activity 上添加 ActionBar。 我在这里提供了我的代码。

My Activity is

public class StatusReport extends TabActivity {

TabHost tabHost;
TabHost.TabSpec tabOnline;
TabHost.TabSpec tabOffline;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_status_report);

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

    tabOnline = tabHost.newTabSpec("Tab 1");
    tabOnline.setContent(R.id.tab1);
    tabOnline.setIndicator("E-Mail",getResources().getDrawable(R.mipmap.ic_launcher));
    Intent in1=new Intent(StatusReport.this,OnlineDevices.class);
    tabOnline.setContent(in1);

    tabOffline = tabHost.newTabSpec("Tab 2");
    tabOffline.setContent(R.id.tab2);
    tabOffline.setIndicator("Messages",getResources().getDrawable(R.mipmap.ic_launcher));
    Intent in2=new Intent(StatusReport.this,OfflineDevices.class);
    tabOffline.setContent(in2);

    tabHost.addTab(tabOnline);
    tabHost.addTab(tabOffline);
}

}

将 extends TabActivity 更改为 AppCompatActivity

private SectionsPagerAdapter sectionsPagerAdapter;
private ViewPager viewPager;
View view = inflater.inflate(R.layout.your_layout, container);

sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
viewPager = (ViewPager)view.findViewById(R.id.pager);
viewPager.setAdapter(sectionsPagerAdapter);

我强烈建议您使用 PagerSlidingTabStrip。 您可以从这里找到它:https://github.com/astuetz/PagerSlidingTabStrip

您可以将其与工具栏一起使用。 https://developer.android.com/reference/android/widget/Toolbar.html