国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android Tab 控件詳解及實(shí)例

2019-10-23 18:33:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Android Tab 控件詳解及實(shí)例

在桌面應(yīng)用中Tab控件使用得非常普遍,那么我們經(jīng)常在Android中也見(jiàn)到以Tab進(jìn)行布局的客戶端。那么Android中的Tab是如何使用的呢?

1.Activity

package com.wicresoft.activity;  import com.wicresoft.myandroid.R;  import android.app.TabActivity; import android.os.Bundle; import android.util.Log; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener;  @SuppressWarnings("deprecation") public class mainActivity extends TabActivity {   private TabHost tabhost;   @Override   protected void onCreate(Bundle savedInstanceState){     super.onCreate(savedInstanceState);     setContentView(R.layout.main_activity);     //從TabActivity上面獲取放置Tab的TabHost     tabhost = getTabHost();     tabhost.addTab(tabhost          //創(chuàng)建新標(biāo)簽one         .newTabSpec("one")         //設(shè)置標(biāo)簽標(biāo)題         .setIndicator("紅色")         //設(shè)置該標(biāo)簽的布局內(nèi)容         .setContent(R.id.widget_layout_red));     tabhost.addTab(tabhost         .newTabSpec("two")         .setIndicator("黃色")         .setContent(R.id.widget_layout_yellow));     tabhost.addTab(tabhost         .newTabSpec("three")         .setIndicator("藍(lán)色")         .setContent(R.id.widget_layout_blue));     tabhost.setOnTabChangedListener(listener);   }      private OnTabChangeListener listener = new OnTabChangeListener(){     @Override     public void onTabChanged(String arg0) {       // TODO Auto-generated method stub       Log.i("TabChange", arg0);     }   }; } 

2.布局文件

<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:id="@android:id/tabhost">  <LinearLayout   android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">    <TabWidget     android:layout_width="match_parent"    android:layout_height="wrap_content"    android:id="@android:id/tabs">  </TabWidget>    <FrameLayout     android:layout_width="match_parent"    android:layout_height="0dp"    android:layout_weight="1"    android:id="@android:id/tabcontent">    <LinearLayout       android:layout_width="match_parent"      android:layout_height="match_parent"      android:id="@+id/widget_layout_red"      android:background="#ff0000"      android:orientation="vertical">    </LinearLayout>         <LinearLayout       android:layout_width="match_parent"      android:layout_height="match_parent"      android:id="@+id/widget_layout_yellow"      android:background="#FCD209"      android:orientation="vertical">     </LinearLayout>     <LinearLayout       android:layout_width="match_parent"      android:layout_height="match_parent"      android:id="@+id/widget_layout_blue"      android:background="#0000E3"      android:orientation="vertical">     </LinearLayout>  </FrameLayout> </LinearLayout></TabHost>

3.Manifest文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"  package="com.wicresoft.myandroid"  android:versionCode="1"  android:versionName="1.0" >  <uses-sdk    android:minSdkVersion="8"    android:targetSdkVersion="19" />  <application    android:allowBackup="true"    android:icon="@drawable/ic_launcher"    android:label="@string/app_name"    android:theme="@style/AppTheme" >    <activity      android:name="com.wicresoft.activity.mainActivity"      android:label="@string/app_name">      <intent-filter>        <action android:name="android.intent.action.MAIN"/>        <category android:name="android.intent.category.LAUNCHER"/>      </intent-filter>    </activity>  </application></manifest>

4.效果

 

Android,Tab,控件,Tab詳解及實(shí)例

Android,Tab,控件,Tab詳解及實(shí)例

Android,Tab,控件,Tab詳解及實(shí)例

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開(kāi)發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新郑市| 韶关市| 安庆市| 临澧县| 鄂托克旗| 布拖县| 赣州市| 林芝县| 咸阳市| 昌乐县| 尚志市| 崇州市| 乐昌市| 门头沟区| 洞头县| 安化县| 盱眙县| 阳原县| 黄陵县| 门头沟区| 年辖:市辖区| 崇信县| 姚安县| 鹰潭市| 灵山县| 天镇县| 蒲城县| 沙河市| 丰宁| 栾城县| 友谊县| 社旗县| 将乐县| 邵阳市| 南乐县| 霍州市| 黎川县| 静海县| 温州市| 奉化市| 南通市|