Android Tab 控件詳解及實(shí)例
Android Tab 控件詳解及實(shí)例
在桌面應(yīng)用中Tab控件使用得非常普遍,那么我們經(jīng)常在Android中也見到以Tab進(jìn)行布局的客戶端。那么Android中的Tab是如何使用的呢?
1.Activity
package com.wicresoft.activity; import com.wicresoft.myandroid.R; import android.app.TabActivity; import android.os.Bundle; import android.util.Log; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; @SuppressWarnings("deprecation") public class mainActivity extends TabActivity { private TabHost tabhost; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); //從TabActivity上面獲取放置Tab的TabHost tabhost = getTabHost(); tabhost.addTab(tabhost //創(chuàng)建新標(biāo)簽one .newTabSpec("one") //設(shè)置標(biāo)簽標(biāo)題 .setIndicator("紅色") //設(shè)置該標(biāo)簽的布局內(nèi)容 .setContent(R.id.widget_layout_red)); tabhost.addTab(tabhost .newTabSpec("two") .setIndicator("黃色") .setContent(R.id.widget_layout_yellow)); tabhost.addTab(tabhost .newTabSpec("three") .setIndicator("藍(lán)色") .setContent(R.id.widget_layout_blue)); tabhost.setOnTabChangedListener(listener); } private OnTabChangeListener listener = new OnTabChangeListener(){ @Override public void onTabChanged(String arg0) { // TODO Auto-generated method stub Log.i("TabChange", arg0); } }; }
2.布局文件
<?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabhost"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"> </TabWidget> <FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="@android:id/tabcontent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/widget_layout_red" android:background="#ff0000" android:orientation="vertical"> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/widget_layout_yellow" android:background="#FCD209" android:orientation="vertical"> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/widget_layout_blue" android:background="#0000E3" android:orientation="vertical"> </LinearLayout> </FrameLayout> </LinearLayout> </TabHost>
3.Manifest文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wicresoft.myandroid" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.wicresoft.activity.mainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
4.效果
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
- Android MarginDesign控件TabLayout導(dǎo)航欄使用詳解
- Android Navigation TabBar控件實(shí)現(xiàn)多彩標(biāo)簽欄
- 詳解Android中ViewPager的PagerTabStrip子控件的用法
- Android控件之TabHost用法實(shí)例分析
- android TabHost(選項(xiàng)卡)的使用方法
- android 選項(xiàng)卡(TabHost)如何放置在屏幕的底部
- Android TabLayout(選項(xiàng)卡布局)簡單用法實(shí)例分析
- Android仿微信底部實(shí)現(xiàn)Tab選項(xiàng)卡切換效果
- Android多個(gè)TAB選項(xiàng)卡切換效果
- Android實(shí)現(xiàn)網(wǎng)易Tab分類排序控件實(shí)現(xiàn)
相關(guān)文章
Android自定義View實(shí)現(xiàn)游戲搖桿鍵盤的方法示例
Android進(jìn)階過程中有一個(gè)繞不開的話題——自定義View。最近在做項(xiàng)目中又遇到了,所以下面這篇文章主要給大家介紹了利用Android自定義View實(shí)現(xiàn)游戲搖桿鍵盤的相關(guān)資料,操作方式類似王者榮耀的搖桿操作,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面來一起看看吧。2017-07-07探討:android項(xiàng)目開發(fā) 統(tǒng)籌兼顧 需要考慮的因素
本篇文章是對基于android項(xiàng)目開發(fā) 統(tǒng)籌兼顧 需要考慮的因素進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06Android自定義RadioGroupX實(shí)現(xiàn)多行多列布局
這篇文章主要為大家詳細(xì)介紹了Android自定義RadioGroupX實(shí)現(xiàn)多行多列布局,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Android中定時(shí)執(zhí)行任務(wù)的3種實(shí)現(xiàn)方法(推薦)
下面小編就為大家?guī)硪黄狝ndroid中定時(shí)執(zhí)行任務(wù)的3種實(shí)現(xiàn)方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11Android 自定View實(shí)現(xiàn)仿QQ運(yùn)動(dòng)步數(shù)圓弧及動(dòng)畫效果
這篇文章主要介紹了Android自定義view實(shí)現(xiàn)高仿QQ運(yùn)動(dòng)步數(shù)圓弧及動(dòng)畫效果的實(shí)例代碼,本文涉及到繪制圓弧需要具備的知識(shí)點(diǎn),需要的朋友可以參考下2016-10-10Android?Studio實(shí)現(xiàn)簡易計(jì)算器設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了Android?Studio實(shí)現(xiàn)簡易計(jì)算器設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05Android協(xié)程的7個(gè)重要知識(shí)點(diǎn)匯總
在現(xiàn)代Android應(yīng)用開發(fā)中,協(xié)程(Coroutine)已經(jīng)成為一種不可或缺的技術(shù),它不僅簡化了異步編程,還提供了許多強(qiáng)大的工具和功能,可以在高階場景中發(fā)揮出色的表現(xiàn),本文將深入探討Coroutine重要知識(shí)點(diǎn),幫助開發(fā)者更好地利用Coroutine來構(gòu)建高效的Android應(yīng)用2023-09-09