欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開(kāi)發(fā)之TabActivity用法實(shí)例詳解

 更新時(shí)間:2016年03月02日 09:11:10   作者:炫_(tái)愛(ài)羊  
這篇文章主要介紹了Android開(kāi)發(fā)之TabActivity用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android擴(kuò)展Activity實(shí)現(xiàn)標(biāo)簽頁(yè)效果的具體步驟與相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開(kāi)發(fā)之TabActivity用法。分享給大家供大家參考,具體如下:

一.簡(jiǎn)介

TabActivity繼承自Activity,目的是讓同一界面容納更多的內(nèi)容。TabActivity實(shí)現(xiàn)標(biāo)簽頁(yè)的功能,通過(guò)導(dǎo)航欄對(duì)各個(gè)頁(yè)面進(jìn)行管理。

二.XML布局文件

注意:

1.TabActivity的布局文件要求以TabHost作為XML布局文件的根。

2.通常我們采用線性布局,所以<TabHost> 的子元素是 <LinearLayout>。

3.<TabWidget>對(duì)應(yīng)Tab
<FrameLayout>則用于包含Tab需要展示的內(nèi)容
需要注意的是<TabWidget> 和<FrameLayout>的Id 必須使用系統(tǒng)id,分別為android:id/tabs 和 android:id/tabcontent 。
因?yàn)橄到y(tǒng)會(huì)使用者兩個(gè)id來(lái)初始化TabHost的兩個(gè)實(shí)例變量(mTabWidget 和 mTabContent)。

4.代碼示例

<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@android:id/tabhost"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
  <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
  <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
  </TabWidget>
  <FrameLayout android:id="@android:id/tabcontent"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</TabHost>

三.TabActivity

1.TabHost:TabHost是Tab的載體,用來(lái)管理Tab。

2.TabHost的一些函數(shù)

(1)獲取

TabHost tabHost=this.getTabHost();

(2) 創(chuàng)建TabHost.TabSpec

public TabHost.TabSpec newTabSpec (String tag)

(3)添加tab

public void addTab (TabHost.TabSpec tabSpec)

(4)remove所有的Tabs

public void clearAllTabs ()
public int getCurrentTab ()

(5)  設(shè)置當(dāng)前的Tab (by index)

public void setCurrentTab (int index)

(6) 設(shè)置當(dāng)前的(Tab by tag)

public void setCurrentTabByTag (String tag)

(7)設(shè)置TabChanged事件的響應(yīng)處理

public void setOnTabChangedListener (TabHost.OnTabChangeListener l)

3.TabHost.TabSpec要設(shè)置tab的label和content,需要設(shè)置TabHost.TabSpec類(lèi)。TabHost.TabSpec管理:

public String getTag ()
public TabHost.TabSpec setContent
public TabHost.TabSpec setIndicator

(1)Indicator這里的Indicator 就是Tab上的label,它可以

設(shè)置label :

setIndicator (CharSequence label)

設(shè)置label和icon :

setIndicator (CharSequence label, Drawable icon)

指定某個(gè)view :

setIndicator (View view)

(2)Content對(duì)于Content ,就是Tab里面的內(nèi)容,可以

設(shè)置View的id :

setContent(int viewId)

用new Intent 來(lái)引入其他Activity的內(nèi)容:setContent(Intent intent)

package com.zhanglong.music;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TabHost;
public class MainActivity extends TabActivity
{
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
     WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    Resources res = getResources();
    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec;
    Intent intent;
    intent = new Intent().setClass(this, ListActivity.class);
    spec = tabHost.newTabSpec("音樂(lè)").setIndicator("音樂(lè)",
             res.getDrawable(R.drawable.item))
           .setContent(intent);
    tabHost.addTab(spec);
    intent = new Intent().setClass(this, ArtistsActivity.class);
    spec = tabHost.newTabSpec("藝術(shù)家").setIndicator("藝術(shù)家",
             res.getDrawable(R.drawable.artist))
           .setContent(intent);
    tabHost.addTab(spec);
    intent = new Intent().setClass(this, AlbumsActivity.class);
    spec = tabHost.newTabSpec("專(zhuān)輯").setIndicator("專(zhuān)輯",
             res.getDrawable(R.drawable.album))
           .setContent(intent);
    tabHost.addTab(spec);
    intent = new Intent().setClass(this, SongsActivity.class);
    spec = tabHost.newTabSpec("最近播放").setIndicator("最近播放",
             res.getDrawable(R.drawable.album))
           .setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(0);
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android TextView對(duì)齊的兩種方法

    Android TextView對(duì)齊的兩種方法

    這篇文章主要介紹了Android TextView對(duì)齊的兩種方法的相關(guān)資料,在開(kāi)發(fā)Android APP 的時(shí)候經(jīng)常會(huì)用到TextView 輸入用戶(hù)信息或者其他信息,總是不能對(duì)齊,這里提供兩種方法,需要的朋友可以參考下
    2017-07-07
  • Android實(shí)現(xiàn)圖片在屏幕內(nèi)縮放和移動(dòng)效果

    Android實(shí)現(xiàn)圖片在屏幕內(nèi)縮放和移動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Android控制圖片在屏幕內(nèi)縮放和移動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案

    Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案

    這篇文章主要為大家介紹了Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • 通俗易通講解Android藍(lán)牙鍵值適配

    通俗易通講解Android藍(lán)牙鍵值適配

    這篇文章介紹了Android藍(lán)牙鍵值適配的方法,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值。需要的朋友可以收藏下,方便下次瀏覽觀看
    2021-12-12
  • flutter的環(huán)境安裝配置問(wèn)題及解決方法

    flutter的環(huán)境安裝配置問(wèn)題及解決方法

    Flutter是Google推出的基于Dart語(yǔ)言開(kāi)發(fā)的跨平臺(tái)開(kāi)源UI框架,旨在統(tǒng)一紛紛擾擾的跨平臺(tái)開(kāi)發(fā)框架,在UI層面上多端共用一套Dart代碼來(lái)實(shí)現(xiàn)多平臺(tái)適配開(kāi)發(fā),這篇文章主要介紹了flutter的環(huán)境安裝配置問(wèn)題,需要的朋友可以參考下
    2020-06-06
  • Android自定義彈窗提醒控件使用詳解

    Android自定義彈窗提醒控件使用詳解

    這篇文章主要為大家詳細(xì)介紹了Android自定義彈窗提醒控件的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android中Glide加載到RelativeLayout背景圖方法示例

    Android中Glide加載到RelativeLayout背景圖方法示例

    Glide框架大家應(yīng)該都很熟悉,我們可以使用Glide加載網(wǎng)絡(luò)圖片、加載gif圖片,使用簡(jiǎn)單。下面這篇文章主要給大家介紹了關(guān)于Android中Glide加載到RelativeLayout背景圖的相關(guān)資料,需要的朋友可以參考下。
    2017-12-12
  • Android Button點(diǎn)擊事件的四種實(shí)現(xiàn)方法

    Android Button點(diǎn)擊事件的四種實(shí)現(xiàn)方法

    這篇文章主要為大家詳細(xì)介紹了Android Button點(diǎn)擊事件的四種實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android自定義View實(shí)現(xiàn)選座功能

    Android自定義View實(shí)現(xiàn)選座功能

    這篇文章主要介紹了Android自定義View實(shí)現(xiàn)選座功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-09-09
  • android自定義對(duì)話框?qū)嵗a

    android自定義對(duì)話框?qū)嵗a

    大家好,本篇文章主要講的是android自定義對(duì)話框?qū)嵗a,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12

最新評(píng)論