欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

2011.09.14(3)——— android 自定義tabhost

系統(tǒng) 2013 0
2011.09.14(3)——— android 自定義tabhost的tabs
參考: http://www.cnblogs.com/over140/archive/2011/03/02/1968042.html
    http://www.iteye.com/topic/1116261
  


我們直接用系統(tǒng)的tabhost時(shí) 如下圖
2011.09.14(3)——— android 自定義tabhost的tabs

可以看見 兩個(gè)tab中間有空隙 也許我們不需要這些空隙或者系統(tǒng)的樣式 但是沒有相關(guān)的xml屬性來(lái)修改 所以我們可以自定義tabs
效果如下圖 可以看見 沒有了中間的空隙



我們用單選按鈕來(lái)實(shí)現(xiàn)tabs


1、看布局文件

    <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@android:id/tabhost"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:background = "#d7d7d7">
	<LinearLayout android:orientation="vertical"
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent">
		<FrameLayout android:id="@android:id/tabcontent"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_weight = "1">			
		</FrameLayout>	
		
		<TabWidget android:id="@android:id/tabs"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:visibility = "gone"/>
		 <RadioGroup android:gravity="right" 
		 			android:layout_gravity="bottom" 
		 			android:orientation="horizontal" 
		 			android:id="@+id/main_radio"		 			 
		 			android:layout_width="fill_parent" 
		 			android:layout_height="wrap_content">
		 	
		 	<RadioButton 
            	android:id="@+id/radio_contact" 
            	android:layout_marginTop="2.0dip"
            	android:background = "@drawable/tabcontact"
            	android:layout_width="wrap_content" 
		 		android:layout_height="fill_parent"
		 		android:button= "@null"      
            	/>
            <RadioButton android:checked="true"            	 
            	android:id="@+id/radio_session" 
            	android:layout_marginTop="2.0dip"
            	android:background = "@drawable/tabsession"
            	android:layout_width="wrap_content" 
		 		android:layout_height="fill_parent"
		 		android:button= "@null"/>  
		 	<RadioButton 
            	android:id="@+id/radio_setting" 
            	android:layout_marginTop="2.0dip"
            	android:background = "@drawable/tabsetting"
            	android:layout_width="wrap_content" 
		 		android:layout_height="fill_parent"
		 		android:button= "@null"
            	/>                               
        </RadioGroup>			
	</LinearLayout>		
</TabHost>


  


關(guān)鍵 在于 TabWidget里面
    android:visibility = "gone"
  


2、代碼

主要是三個(gè)方法:

初始化Tabhost
    private void initTabHost() {
		mTabHost = getTabHost();
		mTabHost.addTab(mTabHost.newTabSpec("tab session").setIndicator(
				"").setContent(new Intent(this,SessionListActivity.class)));
		mTabHost.addTab(mTabHost.newTabSpec("tab contact").setIndicator(
				"").setContent(new Intent(this,ContactListActivity.class)));
		mTabHost.addTab(mTabHost.newTabSpec("tab setting").setIndicator(
				"").setContent(new Intent(this,UserSettingActivitiy.class)));
		
		mTabHost.setCurrentTabByTag(_contactListTag);
		mTabHost.setCurrentTabByTag(_settingTag);
		mTabHost.setCurrentTabByTag(_sessionListTag);
		
	}
  


初始化RadioButton
    private void initTabWidget() {
	     ((RadioButton) findViewById(R.id.radio_session)).setOnCheckedChangeListener(this);
         ((RadioButton) findViewById(R.id.radio_contact)).setOnCheckedChangeListener(this);
         ((RadioButton) findViewById(R.id.radio_setting)).setOnCheckedChangeListener(this);
	}
  


設(shè)置切換事件
??
     @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            switch (buttonView.getId()) {
            case R.id.radio_contact:
                this.mTabHost.setCurrentTabByTag(_contactListTag);
                break;
            case R.id.radio_session:
                this.mTabHost.setCurrentTabByTag(_sessionListTag);
                break;
            case R.id.radio_setting:
            	this.mTabHost.setCurrentTabByTag(_settingTag);
                break;            
            }
        }
    }
  



1.  由于TabWidget被隱藏,所以相關(guān)的事件也會(huì)無(wú)效,這里取巧用RadioGroup與RadioButton的特性來(lái)處理切換,然后監(jiān)聽事件調(diào)用setCurrentTabByTag來(lái)切換Activity。
2.  注意即使TabWidget被隱藏,也要為其設(shè)置indicator,否則會(huì)保持。



2011.09.14(3)——— android 自定義tabhost的tabs


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 亚洲码在线 | 久操久热 | 狠狠操操 | 亚洲性69影院在线观看 | 国产免费叼嘿在线观看 | 99久久精品免费 | 精品a级片 | 国产免费又色又爽又黄的网站 | 黄色一级大片在线免费看产 | 狠狠干av | 午夜精品久久久久久 | 91精品天美精东蜜桃传媒免费 | 午夜激情视频免费 | 欧美操穴| 天天操夜夜操天天操 | 免费能直接在线观看黄的视频 | 国产精品久久久久久无码人妻 | 国产一区中文字幕 | 免费一级毛片 | 一区二区高清 | 538prom国产在线视频一区 | 国产麻豆传媒视频 | 久久亚洲美女久久久久 | 二区在线观看 | ak福利视频 | 一级片在线免费观看视频 | 国产成人99久久亚洲综合精品 | 成年免费大片黄在线观看岛国 | 欧美激情一区二区三区视频高清 | 国产色产综合色产在线观看视频 | 欧美videosex性极品hd | 成人在线观看av | 91成人午夜性a一级毛片 | 日韩a无v码在线播放免费 | 91文字幕巨乱亚洲香蕉 | 日日夜夜精品视频 | 日韩精品亚洲人成在线播放 | 日韩高清一区二区 | 能看的av网站 | 大毛片| 天天干干|