<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    The important thing in life is to have a great aim , and the determination

    常用鏈接

    統(tǒng)計(jì)

    IT技術(shù)鏈接

    保險(xiǎn)相關(guān)

    友情鏈接

    基金知識(shí)

    生活相關(guān)

    最新評(píng)論

    修改TabHost默認(rèn)樣式(文字居中)

    修改TabHost默認(rèn)樣式

    TabHost是Android提供的一個(gè)容器組件,利用它可以輕松地實(shí)現(xiàn)TAB界面,如下圖所示:

    但很多時(shí)候,默認(rèn)的TAB樣式并不符合軟件的整體風(fēng)格,這時(shí)候該怎么辦呢?其實(shí),我們可以編寫(xiě)XML對(duì)其樣式進(jìn)行修改。下面修改后的效果圖:

    1. TabHost布局文件 main.xml

    	<TabHost
    	    android:id="@+id/tabhost"  
    	    android:layout_width="fill_parent"
    	    android:layout_height="fill_parent">
    <LinearLayout  
    	        android:orientation="vertical"
    	        android:layout_width="fill_parent"  
    	        android:layout_height="fill_parent">
    <TabWidget  
    	            android:id="@android:id/tabs"
    	            android:layout_width="fill_parent" 
    	            android:layout_height="30dip"
    	            android:background="#a0a0a0"
    	            android:layout_weight="0" />
    <FrameLayout  
    	            android:id="@android:id/tabcontent"  
    	            android:layout_width="fill_parent"  
    	            android:layout_height="fill_parent"
    	            android:layout_weight="1">
    <ListView 
    				    android:id="@+id/user_list"
    				    android:layout_width="fill_parent"
    				    android:layout_height="fill_parent" 
    				    android:divider="@drawable/divider_line"
    				    android:cacheColorHint="#00000000" />
    <ListView 
    				    android:id="@+id/article_list"
    				    android:layout_width="fill_parent"
    				    android:layout_height="fill_parent" 
    				    android:divider="@drawable/divider_line"
    				    android:cacheColorHint="#00000000" />
    <ListView 
    				    android:id="@+id/feed_list"
    				    android:layout_width="fill_parent"
    				    android:layout_height="fill_parent" 
    				    android:divider="@drawable/divider_line"
    				    android:cacheColorHint="#00000000" />
    <ListView 
    				    android:id="@+id/book_list"
    				    android:layout_width="fill_parent"
    				    android:layout_height="fill_parent" 
    				    android:divider="@drawable/divider_line"
    				    android:cacheColorHint="#00000000" />
    </FrameLayout>
    </LinearLayout>
    </TabHost>


    FrameLayout里有四個(gè)ListView 分別對(duì)應(yīng)用戶、文章、頻道、圖書(shū)。
    TabWidget和FrameLayout的ID不能自己定義修改。




    2. Activity后臺(tái)代碼
    RelativeLayout articleTab = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.minitab, null);
                TextView articleTabLabel = (TextView) articleTab.findViewById(R.id.tab_label);
                articleTabLabel.setText("文章");
                 
                RelativeLayout feedTab = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.minitab, null);
                TextView feedTabLabel = (TextView) feedTab.findViewById(R.id.tab_label);
                feedTabLabel.setText("頻道");
                 
                RelativeLayout bookTab = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.minitab, null);
                TextView bookTabLabel = (TextView) bookTab.findViewById(R.id.tab_label);
                bookTabLabel.setText("圖書(shū)");
                 
                TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
                tabHost.setup();
                 
                tabHost.addTab(tabHost.newTabSpec("user").setIndicator(userTab).setContent(R.id.user_list));
                tabHost.addTab(tabHost.newTabSpec("article").setIndicator(articleTab).setContent(R.id.article_list));
                tabHost.addTab(tabHost.newTabSpec("feed").setIndicator(feedTab).setContent(R.id.feed_list));
                tabHost.addTab(tabHost.newTabSpec("book").setIndicator(bookTab).setContent(R.id.book_list));


    TabHost創(chuàng)建出來(lái)以后,必須先setup一下,tabHost.setup();

    setIndicator方法設(shè)置的View其實(shí)就對(duì)應(yīng)了TAB中的一個(gè)個(gè)選項(xiàng)卡,它們都是通過(guò)一個(gè)叫minitab的布局文件inflate出來(lái)的
    3. 選項(xiàng)卡布局文件minitab.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingLeft="5dip"
        android:paddingRight="5dip">
     
    <TextView android:id="@+id/tab_label"  
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:textColor="#000000"
            android:textStyle="bold"
            android:background="@drawable/minitab" />
    </RelativeLayout>

    drawable/minitab是一個(gè)selector,指定了Tab選項(xiàng)卡的背景顏色。

    4. selector文件 minitab.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector
    	xmlns:android="http://schemas.android.com/apk/res/android"
    	>
    <item
    		android:state_selected="false"
    		android:drawable="@drawable/minitab_unselected"
    		>
    </item>
    <item
    		android:state_selected="true"
    		android:drawable="@drawable/minitab_default"
    		>
    </item>
    </selector>


    minitab_unselected是一淺藍(lán)色背景圖片
    minitab_default是一白色背景圖片




    posted on 2011-02-16 11:28 鴻雁 閱讀(5991) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): IT技術(shù)相關(guān)

    主站蜘蛛池模板: 久久青青草原亚洲av无码app| 久久精品乱子伦免费| 亚洲国产中文在线视频| 亚洲性久久久影院| 午夜高清免费在线观看| 日本免费人成在线网站| 久久免费高清视频| 久久国产精品免费一区| 国产天堂亚洲国产碰碰| 亚洲中文无码亚洲人成影院| 久久精品国产亚洲AV高清热| 国产亚洲一区二区三区在线观看 | 国产乱子伦片免费观看中字| 国产成人免费在线| 久久狠狠躁免费观看| 中文无码日韩欧免费视频| 色爽黄1000部免费软件下载| 亚洲av乱码中文一区二区三区| 亚洲香蕉在线观看| 亚洲不卡1卡2卡三卡2021麻豆| 亚洲视频免费在线观看| 亚洲av永久无码制服河南实里| 亚洲视频在线免费| 亚洲国产精品视频| 亚洲国产a级视频| 亚洲AV成人精品日韩一区18p| 国产成人免费全部网站| 日本不卡视频免费| 日韩免费视频网站| 国产免费黄色大片| 免费人成视频x8x8入口| 国产乱人免费视频| 亚洲国产精品一区二区第四页| 亚洲JIZZJIZZ中国少妇中文| 亚洲性久久久影院| 久久精品国产亚洲网站| 亚洲伊人tv综合网色| 亚洲制服在线观看| 亚洲AV日韩综合一区尤物| 美国毛片亚洲社区在线观看| 免费视频成人国产精品网站|