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 跨進(jìn)程通Messenger(簡單易懂)
這篇文章主要介紹了Android Messenger跨進(jìn)程通的相關(guān)資料,非常簡單容易理解,對android messenger 進(jìn)程通訊的相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-08-08
Android Studio 實(shí)現(xiàn)將support庫改成Androidx
這篇文章主要介紹了Android Studio 實(shí)現(xiàn)將support庫改成Androidx,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04
OpenGL關(guān)于glStencilFuncSeparate()和glStencilFunc()函數(shù)的區(qū)別講解
今天小編就為大家分享一篇OpenGL關(guān)于glStencilFuncSeparate()和glStencilFunc()函數(shù)的區(qū)別講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-04-04
設(shè)置Android系統(tǒng)永不鎖屏永不休眠的方法
在進(jìn)行Android系統(tǒng)開發(fā)的時(shí)候,有些特定的情況需要設(shè)置系統(tǒng)永不鎖屏,永不休眠。本篇文章給大家介紹Android 永不鎖屏,開機(jī)不鎖屏,刪除設(shè)置中休眠時(shí)間選項(xiàng),需要的朋友一起學(xué)習(xí)吧2016-03-03
詳解Android應(yīng)用中preference首選項(xiàng)的編寫方法
這篇文章主要介紹了Android應(yīng)用中preference首選項(xiàng)的編寫方法,或許Apple將其翻譯為'偏好設(shè)置'更直觀些,即用戶對應(yīng)用的一些個(gè)性化調(diào)整菜單,需要的朋友可以參考下2016-04-04
Android App中的多個(gè)LinearLayout嵌套布局實(shí)例解析
這篇文章主要介紹了Android App中的多個(gè)LinearLayout嵌套布局實(shí)例,利用線性布局來排列按鈕是安卓應(yīng)用布局中的常用做法,需要的朋友可以參考下2016-04-04
Android?Flutter實(shí)現(xiàn)在多端運(yùn)行的掃雷游戲
當(dāng)我們回憶起小時(shí)候的經(jīng)典電腦游戲,掃雷一定是其中之一。本文將通過Flutter實(shí)現(xiàn)一個(gè)能在多端運(yùn)行的掃雷游戲,感興趣的可以了解一下2023-03-03

