现在的位置: 首页 > 综合 > 正文

底部tabhost研究一(TabHost 不是最外面的布局)

2013年01月30日 ⁄ 综合 ⁄ 共 3693字 ⁄ 字号 评论关闭

 

  各位大侠请自行把代码放到项目中去。没有给的activity自己手写几个。然后替换就可以了     运行不出来的请联系我。

 

  1. import android.app.ActivityGroup;  
  2. import android.content.Intent;  
  3. import android.os.Bundle;  
  4. import android.widget.TabHost;  
  5. import android.widget.TabHost.TabSpec;  
  6.   
  7. public class MainActivity extends ActivityGroup {  
  8.     public  TabHost tab_host;  
  9.     @Override  
  10.     protected void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.         setContentView(R.layout.main);  
  13.         tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);  
  14.         tab_host.setup(this.getLocalActivityManager());  
  15.         tab_host.setPadding(tab_host.getPaddingLeft(),  
  16.                 tab_host.getPaddingTop(), tab_host.getPaddingRight(),  
  17.                 tab_host.getPaddingBottom()-10);  
  18.         TabSpec ts1 = tab_host.newTabSpec("TAB_RECOMMEND");  
  19.         ts1.setIndicator("s", getResources().getDrawable(R.drawable.icon));  
  20.         ts1.setContent(new Intent(this, TestActivity.class));  
  21.         tab_host.addTab(ts1);  
  22.   
  23.         TabSpec ts2 = tab_host.newTabSpec("TAB_NEWLY");  
  24.         ts2.setIndicator("s", getResources().getDrawable(R.drawable.icon));  
  25.         ts2.setContent(new Intent(this, TestActivity.class));  
  26.         tab_host.addTab(ts2);  
  27.   
  28.         TabSpec ts3 = tab_host.newTabSpec("TAB_PHB");  
  29.         ts3.setIndicator("s", getResources().getDrawable(R.drawable.icon));  
  30.         ts3.setContent(new Intent(this, TestActivity.class));  
  31.         tab_host.addTab(ts3);  
  32.   
  33.         tab_host.setCurrentTab(0);  
  34.     }  
  35.     
  36. }  

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical" android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent">  
  5.     <TabHost android:id="@+id/edit_item_tab_host"  
  6.         android:layout_width="fill_parent" android:layout_height="fill_parent">  
  7.         <LinearLayout android:orientation="vertical"  
  8.             android:layout_width="fill_parent" android:layout_height="fill_parent"  
  9.             android:padding="5dp">  
  10.             <FrameLayout android:id="@android:id/tabcontent"  
  11.                 android:layout_width="fill_parent" android:layout_height="wrap_content"  
  12.                 android:padding="5dp" android:layout_weight="1" />  
  13.             <TabWidget android:id="@android:id/tabs"  
  14.                 android:layout_width="fill_parent" android:layout_height="wrap_content"  
  15.                 android:layout_weight="0" />  
  16.         </LinearLayout>  
  17.     </TabHost>  
  18. </LinearLayout>  



 

如果把图片做为按钮      去掉外面黑色的背景      加上

 

  1. /* 对Tab标签的定制 */  
  2.      mTabWidget = mTabHost.getTabWidget();  
  3.      for (int i = 0; i < mTabWidget.getChildCount(); i++)  
  4.      {  
  5.          /* 得到每个标签的视图 */  
  6.          View view = mTabWidget.getChildAt(i);  
  7.          /* 设置每个标签的背景 */  
  8.          if (mTabHost.getCurrentTab() == i)  
  9.          {  
  10.             if(i==0){  
  11.                 view.setBackgroundDrawable(getResources().getDrawable(  
  12.                          R.drawable.guide_menu1));  
  13.             }else if(i==1){  
  14.                 view.setBackgroundDrawable(getResources().getDrawable(  
  15.                          R.drawable.guide_menu3));  
  16.             }else if(i==2){  
  17.                 view.setBackgroundDrawable(getResources().getDrawable(  
  18.                          R.drawable.guide_menu5));  
  19.             }else if(i==3){  
  20.                 view.setBackgroundDrawable(getResources().getDrawable(  
  21.                          R.drawable.guide_menu7));  
  22.             }  
  23.              //view.setBackgroundDrawable(getResources().getDrawable(  
  24.              //        R.drawable.home_btn_bg_d));  
  25.          }  
  26.          else  
  27.          {  

抱歉!评论已关闭.