最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開(kāi)發(fā)之選項(xiàng)卡功能的實(shí)現(xiàn)方法示例

 更新時(shí)間:2017年06月28日 10:50:33   作者:聽(tīng)著music睡  
這篇文章主要介紹了Android開(kāi)發(fā)之選項(xiàng)卡功能的實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android選項(xiàng)卡功能的原理、實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Android選項(xiàng)卡功能的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

選項(xiàng)卡(TabHost)方便的在窗口上設(shè)置多個(gè)標(biāo)簽頁(yè),每個(gè)標(biāo)簽頁(yè)相當(dāng)于獲得一個(gè)與外部容器相同大小的組件擺放區(qū)域

通過(guò)這種方式,可以在一個(gè)容器中放置多組件。

創(chuàng)建4個(gè)java文件并對(duì)應(yīng)layout

創(chuàng)建主java ,代碼

package lianxi;
import com.example.jichu_lianxi.R;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class TobHost_lianxi extends TabActivity{
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    //獲取當(dāng)前Activity的標(biāo)簽,該方法的實(shí)現(xiàn)已經(jīng)執(zhí)行了setContentView(com.android.internal.R.layout.tab_content);
    Resources resources = getResources();
    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec;
    /*
     * 對(duì)方法的解釋:
     * 1.   newTabSpec("artist")創(chuàng)建一個(gè)標(biāo)簽項(xiàng),其中artist為它的標(biāo)簽標(biāo)識(shí)符
     * 2.   setIndicator("標(biāo)簽1", resources.getDrawable(R.drawable.bulb_off))
     *      顯示文本以及標(biāo)簽上的圖標(biāo)(該圖標(biāo)不是一個(gè)圖片,而是一個(gè)xml文件)
     */
    //添加第一個(gè)標(biāo)簽
    Intent intent = new Intent(TobHost_lianxi.this,KeyOnclick.class);
    spec = tabHost.newTabSpec("keyonclick").setIndicator("標(biāo)簽1", resources.getDrawable(R.drawable.bulb_off)).setContent(intent);
    tabHost.addTab(spec);//將標(biāo)簽添加到標(biāo)簽項(xiàng)中
    //添加第二個(gè)標(biāo)簽
    Intent intent2 = new Intent(TobHost_lianxi.this,List_lianxi.class);
    spec = tabHost.newTabSpec("list").setIndicator("標(biāo)簽2",resources.getDrawable(R.drawable.bulb_off)).setContent(intent2);
    tabHost.addTab(spec);
    //添加第三個(gè)標(biāo)簽
    Intent intent3 = new Intent(TobHost_lianxi.this,ToggleButton_lianxi.class);
    spec = tabHost.newTabSpec("togglebutton").setIndicator("標(biāo)簽3",resources.getDrawable(R.drawable.bulb_off)).setContent(intent3);
    tabHost.addTab(spec);
    //添加第四個(gè)標(biāo)簽
    Intent intent4 = new Intent(TobHost_lianxi.this,ToggleButton_lianxi.class);
    spec = tabHost.newTabSpec("toggle").setIndicator("標(biāo)簽4",resources.getDrawable(R.drawable.bulb_off)).setContent(intent4);
    tabHost.addTab(spec);
    //設(shè)置第一次打開(kāi)的默認(rèn)顯示的標(biāo)簽,參數(shù)與 .newTabSpec的參數(shù)匹配
    //tabHost.setCurrentTabByTag("toggle");
    //設(shè)置第一次打開(kāi)的默認(rèn)顯示的標(biāo)簽,參數(shù)代表其添加到標(biāo)簽中的順序,位置從0開(kāi)始
    tabHost.setCurrentTab(1);
  }
}

其中 KeyOnclick.java、List_lianxi.java、ToggleButton_lianxi.java 代碼不貼了

不要忘了在AndroidManifest.xml文件中修改代碼

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name="lianxi.Mainactivity">
      <intent-filter
        >
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name="lianxi.NewActivity"></activity>
    <activity android:name="lianxi.AlertDialog_lianxi"></activity>
    <activity android:name="lianxi.Notification_lianxi"></activity>
    <activity android:name="lianxi.KeyOnclick"></activity>
    <activity android:name="lianxi.List_lianxi"></activity>
    <activity android:name="lianxi.ToggleButton_lianxi"></activity>
    <activity android:name="lianxi.TobHost_lianxi"></activity>
</application>

效果圖(第一張為標(biāo)簽2。因?yàn)閠abHost.setCurrentTab(1); 設(shè)置第2個(gè)添加的標(biāo)簽項(xiàng)為默認(rèn)顯示,從0開(kāi)始算)

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

最新評(píng)論

巴东县| 南昌市| 沁源县| 仁怀市| 察隅县| 吉木乃县| 江永县| 礼泉县| 精河县| 永泰县| 孟州市| 内黄县| 仁化县| 公安县| 越西县| 尉氏县| 洪雅县| 广宁县| 泰兴市| 梨树县| 海南省| 宁阳县| 石棉县| 伊川县| 塘沽区| 容城县| 太谷县| 天等县| 清徐县| 阜阳市| 红河县| 利辛县| 东平县| 彭州市| 二连浩特市| 东至县| 金溪县| 金塔县| 朝阳县| 确山县| 工布江达县|