<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)

    主站蜘蛛池模板: 2017亚洲男人天堂一| 国产精品视频免费观看| 人人狠狠综合久久亚洲88| 无码精品人妻一区二区三区免费看 | 亚洲欧美日韩综合久久久| 免费国产在线观看不卡| 久久99免费视频| 亚洲人色大成年网站在线观看| 国产乱码免费卡1卡二卡3卡| 亚洲大码熟女在线观看| 国产免费人视频在线观看免费| 免费国产a理论片| 国产亚洲3p无码一区二区| 国产精品怡红院永久免费| 精品亚洲AV无码一区二区三区| 亚洲精品乱码久久久久久不卡| **aaaaa毛片免费| 一级做α爱过程免费视频| 亚洲人成电影在线观看青青| 亚洲综合亚洲综合网成人| 免费观看美女用震蛋喷水的视频 | 国产亚洲综合久久系列| 国产精品美女午夜爽爽爽免费| 免费播放国产性色生活片| 久久精品亚洲中文字幕无码麻豆 | 久久亚洲精品无码播放| 成人网站免费观看| 免费国产成人18在线观看| 亚洲精品精华液一区二区| 亚洲色精品vr一区二区三区| 精品女同一区二区三区免费站| 日韩少妇内射免费播放| 亚洲电影免费观看| 内射无码专区久久亚洲| 亚洲一区免费在线观看| 国产亚洲美女精品久久久久| 亚洲精品在线电影| 亚洲中文字幕无码不卡电影| 日本午夜免费福利视频| 99在线免费观看| 亚洲aⅴ天堂av天堂无码麻豆|