我使用 TabHost
和 TabSpec
在 android 中创建了一个包含三个选项卡的项目。我扩展了我的
TabActivity
的主要 Activity 问题是 ActionBar
没有显示在应用程序上。我使用了 Holo.Light.DarkActionBar
主题。
主 Activity .java
public class MainActivity extends TabActivity {
TabHost tabhost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabhost=getTabHost();
TabHost.TabSpec homespec=tabhost.newTabSpec("Home");
homespec.setIndicator("Home",null);
Intent homeintent=new Intent(this,HomeActivity.class);
homespec.setContent(homeintent);
TabHost.TabSpec eventspec=tabhost.newTabSpec("Event");
eventspec.setIndicator("Event");
Intent eventintent=new Intent(this,EventActivity.class);
eventspec.setContent(eventintent);
TabHost.TabSpec profilespec=tabhost.newTabSpec("Profile");
profilespec.setIndicator("Profile");
Intent profileintent=new Intent(this,ProfileActivity.class);
profilespec.setContent(profileintent);
tabhost.addTab(homespec);
tabhost.addTab(eventspec);
tabhost.addTab(profilespec);
}
}
activity_main.xml `
<TabHost
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/tabhost"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
/>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
</FrameLayout>
</LinearLayout>
</TabHost>
有没有其他方法可以实现这个也建议我?
最佳答案
在 AndroidManifest.xml 中为此 Activity 设置主题:
<activity android:name=".MainActivity"
android:theme="@android:style/Theme.Holo.Light"/>
转到 activity_main 并点击设计 -> 主题(在顶部栏中,在设备名称和景观旁边)-> list 主题 -> 然后选择您的主题。
编辑: 当然加上这个(如果你不是故意忘记的)
<?xml version="1.0" encoding="utf-8"?>
关于android - ActionBar 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27862812/