android TabHost(選項(xiàng)卡)的使用方法
首先,定義TabHost的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
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>
</TabHost>
其中,TabWidget即是選項(xiàng)卡上面的標(biāo)簽,F(xiàn)rameLayout是選項(xiàng)卡的內(nèi)容。
在Java類文件中定義如下:
public class MainActivity extends TabActivity {
private TabHost my_tabhost;
private TabWidget my_tabwidget;
private int i,k;
private TextView tv;
private String[] tabMenu = { "系統(tǒng)", "硬件", "操作"};
private Intent intent0, intent1, intent2;
private Intent[] intents = { intent0, intent1, intent2};
private TabHost.TabSpec tabSpec0, tabSpec1, tabSpec2, tabSpec3;
private TabHost.TabSpec[] tabSpecs = { tabSpec0, tabSpec1, tabSpec2, tabSpec3};
public static Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 不要窗體標(biāo)題
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main);
my_tabhost = getTabHost();
intent0 = new Intent(this, system.class);
intent1 = new Intent(this, hardware.class);
intent2 = new Intent(this, operation.class);
tabSpec0 = my_tabhost.newTabSpec("system").setIndicator(tabMenu[0],null).
setContent(intent0);
tabSpec1 = my_tabhost.newTabSpec("hardware").setIndicator(tabMenu[1],null).
setContent(intent1);
tabSpec2 = my_tabhost.newTabSpec("operation").setIndicator(tabMenu[2],null).
setContent(intent2);
my_tabhost.addTab(tabSpec1);
my_tabhost.addTab(tabSpec0);
my_tabhost.addTab(tabSpec2);
<br> // 設(shè)置默認(rèn)選中的選項(xiàng)卡為第2個(gè)
my_tabhost.setCurrentTab(1);
}
}
每一個(gè)選項(xiàng)卡對(duì)應(yīng)一個(gè)Intent,每一個(gè)Intent又對(duì)應(yīng)一個(gè)類,選中這個(gè)選項(xiàng)卡時(shí),就顯示對(duì)應(yīng)的類。
運(yùn)行結(jié)果如下:
- Android TabHost如何實(shí)現(xiàn)頂部選項(xiàng)卡
- Android開發(fā)之TabHost選項(xiàng)卡及相關(guān)疑難解決方法
- Android TabHost選項(xiàng)卡標(biāo)簽圖標(biāo)始終不出現(xiàn)的解決方法
- Android組件TabHost實(shí)現(xiàn)頁面中多個(gè)選項(xiàng)卡切換效果
- android 選項(xiàng)卡(TabHost)如何放置在屏幕的底部
- Android TabLayout(選項(xiàng)卡布局)簡單用法實(shí)例分析
- Android多個(gè)TAB選項(xiàng)卡切換效果
- Android實(shí)現(xiàn)底部導(dǎo)航欄功能(選項(xiàng)卡)
- Android仿微信底部實(shí)現(xiàn)Tab選項(xiàng)卡切換效果
- android選項(xiàng)卡TabHost功能用法詳解
相關(guān)文章
Android 4.4以上"沉浸式"狀態(tài)欄效果的實(shí)現(xiàn)方法
Android與ios效果互仿早已不是什么稀奇的事,我猜大概這個(gè)效果來自ios吧,有爭議說這種效果不能叫做沉浸式,叫透明狀態(tài)欄更合適,我也感覺這和沉浸式的含義不太一致。但是大家都這么叫了,那就這樣唄。下面來一起看看關(guān)于Android 4.4以上"沉浸式"效果的實(shí)現(xiàn)方法。2016-09-09
TextView顯示文本控件兩種方法 TextView顯示link的方法
這篇文章主要為大家詳細(xì)介紹了TextView顯示文本控件兩種方法,TextView顯示link的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Android實(shí)現(xiàn)高德地圖首頁效果(下)
這篇文章主要為大家詳細(xì)介紹了基于Android實(shí)現(xiàn)高德地圖首頁效果下篇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2023-08-08
Android實(shí)現(xiàn)讀寫JSON數(shù)據(jù)的方法
這篇文章主要介紹了Android實(shí)現(xiàn)讀寫JSON數(shù)據(jù)的方法,以完整實(shí)例形式分析了Android解析及生成json數(shù)據(jù)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
Android使用ScrollView實(shí)現(xiàn)滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android使用ScrollView實(shí)現(xiàn)滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01
Studio 編譯報(bào)錯(cuò):compileSdkVersion ''android-24'' requires JDK 1.
今天小編就為大家分享一篇關(guān)于Studio編譯報(bào)錯(cuò):compileSdkVersion 'android-24' requires JDK 1.8 or later to compile.的解決辦法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-10-10
Android自定義豎排TextView實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了Android自定義豎排TextView實(shí)現(xiàn)實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android選擇與上傳圖片之PictureSelector教程
這篇文章主要介紹了在Android中對(duì)于圖片的選擇與上傳方法,本文介紹了PictureSelector的相關(guān)使用教程,學(xué)習(xí)Android的同學(xué)進(jìn)來看看吧2021-08-08
Android自定義viewGroup實(shí)現(xiàn)點(diǎn)擊動(dòng)畫效果
這篇文章主要介紹了Android自定義viewGroup實(shí)現(xiàn)點(diǎn)擊動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12

