android選項卡TabHost功能用法詳解
本文實例為大家分享了android選項卡TabHost功能用法,供大家參考,具體內(nèi)容如下
首先定義三個xml文件,分別為l1.xml,l2.xml,l3.xml,每個選項卡的標簽頁的內(nèi)容為一個xml文件。
其中l(wèi)1.xml為:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:orientation="vertical"? ? ? android:id="@+id/l1"> ? ? ? <Button ? ? ? ? android:id="@+id/button1" ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:text="Button" /> ? </LinearLayout>
l2.xml為:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:orientation="vertical"? ? ? android:id="@+id/l2"> ? ? ? <EditText ? ? ? ? android:id="@+id/editText1" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:ems="10" ? ? ? ? android:inputType="textPersonName" > ? ? ? ? ? <requestFocus /> ? ? </EditText> ? ? ? <EditText ? ? ? ? android:id="@+id/editText2" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="wrap_content" ? ? ? ? android:ems="10" ? ? ? ? android:inputType="textPassword" /> ? </LinearLayout>
l3.xml為:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ? ? android:layout_width="match_parent" ? ? android:layout_height="match_parent" ? ? android:orientation="vertical" ? ? android:id="@+id/l3"> ? ? ? <RatingBar ? ? ? ? android:id="@+id/ratingBar1" ? ? ? ? android:layout_width="wrap_content" ? ? ? ? android:layout_height="wrap_content" /> ? </LinearLayout>
TabActivityDemo2.java:
package com.example.wenandroid; ? import android.app.TabActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.widget.TabHost.TabSpec; ? public class TabActivityDemo2 extends TabActivity { ? ?? ?protected void onCreate(Bundle savedInstanceState) { ?? ??? ?// TODO Auto-generated method stub ?? ??? ?super.onCreate(savedInstanceState); ?? ??? ?android.widget.TabHost tab=getTabHost(); ?? ??? ?LayoutInflater lay=LayoutInflater.from(this); ?? ??? ?lay.inflate(R.layout.l1, tab.getTabContentView(),true); ?? ??? ?lay.inflate(R.layout.l2, tab.getTabContentView(),true); ?? ??? ?lay.inflate(R.layout.l3, tab.getTabContentView(),true); ?? ??? ? ?? ??? ?TabSpec t1=tab.newTabSpec("t1"); ?? ??? ?TabSpec t2=tab.newTabSpec("t2"); ?? ??? ?TabSpec t3=tab.newTabSpec("t3"); ?? ??? ? ?? ??? ?t1.setIndicator("選項卡1"); ?? ??? ?t2.setIndicator("選項卡2"); ?? ??? ?t3.setIndicator("選項卡3"); ?? ??? ? ?? ??? ?t1.setContent(R.id.l1); ?? ??? ?t2.setContent(R.id.l2); ?? ??? ?t3.setContent(R.id.l3); ?? ??? ? ?? ??? ?tab.addTab(t1); ?? ??? ?tab.addTab(t2); ?? ??? ?tab.addTab(t3); ?? ?} ? }
效果如下圖:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android TabHost如何實現(xiàn)頂部選項卡
- Android開發(fā)之TabHost選項卡及相關疑難解決方法
- Android TabHost選項卡標簽圖標始終不出現(xiàn)的解決方法
- Android組件TabHost實現(xiàn)頁面中多個選項卡切換效果
- android TabHost(選項卡)的使用方法
- android 選項卡(TabHost)如何放置在屏幕的底部
- Android TabLayout(選項卡布局)簡單用法實例分析
- Android多個TAB選項卡切換效果
- Android實現(xiàn)底部導航欄功能(選項卡)
- Android仿微信底部實現(xiàn)Tab選項卡切換效果
相關文章
Android如何實現(xiàn)動態(tài)滾動波形圖(心電圖)功能
這篇文章主要介紹了Android如何實現(xiàn)動態(tài)滾動波形圖(心電圖)功能,幫助大家更好的理解和學習使用Android,感興趣的朋友可以了解下2021-03-03Android中ListView的幾種常見的優(yōu)化方法總結(jié)
Android中的ListView應該算是布局中幾種最常用的組件之一,本篇文章主要做了三種優(yōu)化總結(jié),有興趣的可以了解一下。2017-02-02kotlin中EditText賦值Type mismatch方式
這篇文章主要介紹了kotlin中EditText賦值Type mismatch方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android系列---JSON數(shù)據(jù)解析的實例
JSON(JavaScript Object Notation)和XML,并稱為客戶端和服務端交互解決方案的倚天劍和屠龍刀,這篇文章主要介紹了Android系列---JSON數(shù)據(jù)解析的實例,有興趣的可以了解一下。2016-11-11Android中Service實時向Activity傳遞數(shù)據(jù)實例分析
這篇文章主要介紹了Android中Service實時向Activity傳遞數(shù)據(jù)的方法,實例分析了Service組件基于線程操作實現(xiàn)數(shù)值實時傳遞的相關技巧,需要的朋友可以參考下2015-09-09Android中實現(xiàn)為TextView添加多個可點擊的文本
這篇文章主要介紹了Android中實現(xiàn)為TextView添加多個可點擊的文本,可實現(xiàn)類似Android社交軟件顯示點贊用戶并通過用戶名稱進入該用戶主頁的功能,是非常實用的技巧,需要的朋友可以參考下2014-09-09Android編程之ActionBar Tabs用法實例分析
這篇文章主要介紹了Android編程之ActionBar Tabs用法,結(jié)合實例形式分析了ActionBar Tabs的功能及Tab切換不同的Fragment的相關實現(xiàn)技巧,需要的朋友可以參考下2017-03-03