android選項(xiàng)卡TabHost功能用法詳解
本文實(shí)例為大家分享了android選項(xiàng)卡TabHost功能用法,供大家參考,具體內(nèi)容如下
首先定義三個(gè)xml文件,分別為l1.xml,l2.xml,l3.xml,每個(gè)選項(xiàng)卡的標(biāo)簽頁的內(nèi)容為一個(gè)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("選項(xiàng)卡1");
?? ??? ?t2.setIndicator("選項(xiàng)卡2");
?? ??? ?t3.setIndicator("選項(xiàng)卡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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 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 TabHost(選項(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)卡切換效果
相關(guān)文章
android判斷一個(gè)Activity是否處于棧頂?shù)膶?shí)例
下面小編就為大家分享一篇android判斷一個(gè)Activity是否處于棧頂?shù)膶?shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
Android getJSONObject與optJSONObject的區(qū)別結(jié)合源碼分析
這篇文章主要介紹了Android getJSONObject與optJSONObject的區(qū)別,結(jié)合源碼分析的相關(guān)資料,需要的朋友可以參考下2017-02-02
Android自定義View構(gòu)造函數(shù)詳解
這篇文章主要為大家詳細(xì)介紹了Android自定義View構(gòu)造函數(shù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
Android 實(shí)現(xiàn)代碼混淆的實(shí)例
這篇文章主要介紹了Android 實(shí)現(xiàn)代碼混淆的實(shí)例的相關(guān)資料,希望通過本文大家能夠掌握Android代碼混淆的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-09-09
Android帶進(jìn)度條的下載圖片示例(AsyncTask異步任務(wù))
本文主要介紹Android帶進(jìn)度條的下載圖片示例(AsyncTask異步任務(wù))的方法解析。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04
Android入門之Glide顯示網(wǎng)絡(luò)圖片高版本的使用詳解
這篇文章主要為大家詳細(xì)介紹了Android中Glide顯示網(wǎng)絡(luò)圖片高版本的使用方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-02-02

