我想在 Andorid 中创建自定义选项卡。我搜索了很多,但没有找到任何相关的东西。我想创建这样的标签
我的代码产生了这个
我的代码看起来像这样
CustomTabActivity.java
public class CustomTabActivity extends TabActivity {
private TabHost mTabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.setup();
Intent intentAndroid1 = new Intent().setClass(this,Tab1.class);
TabSpec tab1 = mTabHost
.newTabSpec("Android")
.setIndicator("",getResources().getDrawable(R.drawable.icon))
.setContent(intentAndroid1);
Intent intentAndroid2 = new Intent().setClass(this,Tab2.class);
TabSpec tab2 = mTabHost
.newTabSpec("Android")
.setIndicator("",getResources().getDrawable(R.drawable.icon))
.setContent(intentAndroid2);
mTabHost.addTab(tab1);
mTabHost.addTab(tab2);
}
}
主.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>