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)頁(yè)面中多個(gè)選項(xiàng)卡切換效果
- android 選項(xiàng)卡(TabHost)如何放置在屏幕的底部
- Android TabLayout(選項(xiàng)卡布局)簡(jiǎn)單用法實(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的got表HOOK實(shí)現(xiàn)代碼
對(duì)于android的so文件的hook根據(jù)ELF文件特性分為:Got表hook、Sym表hook和inline hook等。今天通過(guò)本文給大家介紹android HOOK實(shí)現(xiàn)got表的實(shí)例代碼,需要的朋友參考下吧2021-08-08
利用Android設(shè)計(jì)一個(gè)倒計(jì)時(shí)組件
在很多電商工作項(xiàng)目中經(jīng)常有倒計(jì)時(shí)的場(chǎng)景,比如活動(dòng)倒計(jì)時(shí)、搶紅包倒計(jì)時(shí)等等,今天小編就帶大家來(lái)學(xué)習(xí)如何利用Android設(shè)計(jì)倒計(jì)時(shí)組件,感興趣的小伙伴一起奧2021-09-09
Android性能優(yōu)化之JVMTI與內(nèi)存分配
這篇文章主要為大家介紹了Android性能優(yōu)化之JVMTI與內(nèi)存分配,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Android便攜式熱點(diǎn)的開啟狀態(tài)檢測(cè)和SSID的獲取方法
WIFI熱點(diǎn)的開啟狀態(tài)和開啟后的SSID如何獲取呢?接下來(lái)通過(guò)本文給大家分享Android便攜式熱點(diǎn)的開啟狀態(tài)檢測(cè)和SSID的獲取方法,需要的朋友參考下吧2017-01-01
Android中Intent傳遞對(duì)象的3種方式詳解
這篇文章給大家介紹了Android中Intent傳遞對(duì)象的3種方式,分別是Serializable 方式、Parcelable 方式以及JSON 方式,有需要的朋友們可以一起參考借鑒,下面來(lái)一起看看吧。2016-09-09
Android videoview搶占焦點(diǎn)的處理方法
這篇文章主要為大家詳細(xì)介紹了Android videoview搶占焦點(diǎn)的處理方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
android實(shí)現(xiàn)okHttp的get和post請(qǐng)求的簡(jiǎn)單封裝與使用
這篇文章主要介紹了android實(shí)現(xiàn)okHttp的get和post請(qǐng)求的簡(jiǎn)單封裝與使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
Android中外接鍵盤的檢測(cè)的實(shí)現(xiàn)
這篇文章主要介紹了Android中外接鍵盤的檢測(cè)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Android Studio獲取網(wǎng)絡(luò)JSON數(shù)據(jù)并處理的方法
這篇文章主要為大家詳細(xì)介紹了Android Studio獲取網(wǎng)絡(luò)JSON數(shù)據(jù)并處理的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10

