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

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ì)方法的解釋?zhuān)?
     * 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)容感興趣的讀者可查看本站專(zhuān)題:《Android開(kāi)發(fā)入門(mén)與進(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)論