<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

    常用鏈接

    統計

    IT技術鏈接

    保險相關

    友情鏈接

    基金知識

    生活相關

    最新評論

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

    修改TabHost默認樣式

    TabHost是Android提供的一個容器組件,利用它可以輕松地實現TAB界面,如下圖所示:

    但很多時候,默認的TAB樣式并不符合軟件的整體風格,這時候該怎么辦呢?其實,我們可以編寫XML對其樣式進行修改。下面修改后的效果圖:

    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里有四個ListView 分別對應用戶、文章、頻道、圖書。
    TabWidget和FrameLayout的ID不能自己定義修改。




    2. Activity后臺代碼
    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("圖書");
                 
                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創建出來以后,必須先setup一下,tabHost.setup();

    setIndicator方法設置的View其實就對應了TAB中的一個個選項卡,它們都是通過一個叫minitab的布局文件inflate出來的
    3. 選項卡布局文件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是一個selector,指定了Tab選項卡的背景顏色。

    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是一淺藍色背景圖片
    minitab_default是一白色背景圖片




    posted on 2011-02-16 11:28 鴻雁 閱讀(5994) 評論(0)  編輯  收藏 所屬分類: IT技術相關

    主站蜘蛛池模板: 免费看男女下面日出水视频| 免费91麻豆精品国产自产在线观看| 97久久免费视频| 亚洲无av在线中文字幕| 在线成人a毛片免费播放| 色老板亚洲视频免在线观| 91精品免费国产高清在线| 国产成人一区二区三区免费视频| 亚洲天然素人无码专区| 最近免费中文字幕大全| 亚洲精品亚洲人成在线| 999zyz**站免费毛片| 亚洲人午夜射精精品日韩| 中国一级毛片视频免费看| 国产AV无码专区亚洲AV手机麻豆| 亚洲fuli在线观看| 91免费资源网站入口| 国产精品亚洲片在线观看不卡| a级午夜毛片免费一区二区| 亚洲久本草在线中文字幕| 国产亚洲精品第一综合| 免费吃奶摸下激烈视频| 亚洲乱码一二三四五六区| 午夜免费不卡毛片完整版| 一区二区三区免费视频网站| 亚洲日韩精品无码专区网址| 3d动漫精品啪啪一区二区免费| 亚洲免费福利在线视频| 亚洲精品和日本精品| 4399影视免费观看高清直播| 亚洲AV成人精品日韩一区| 在线精品亚洲一区二区小说| 24小时日本电影免费看| 99亚洲男女激情在线观看| 亚洲日产无码中文字幕| 99热在线精品免费全部my| 日韩免费码中文在线观看| 777亚洲精品乱码久久久久久 | 亚洲av永久无码精品秋霞电影影院 | 亚洲香蕉久久一区二区三区四区| 四虎永久在线精品免费观看地址|