更多参考:http://www.360doc.com/content/12/0515/13/7857928_211171985.shtml

效果图:

Android之TabHost重定义


TabHost的布局:

<?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" >    <LinearLayout        android:id="@+id/linearLayout1"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical" >        <TabWidget            android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content" >        </TabWidget>        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"            android:layout_height="fill_parent" >        </FrameLayout>    </LinearLayout></TabHost>


TabHost的主文件:

public class MainActivity extends TabActivity {    String[] title = new String[]{"ni","wo","ta","we"};      View userTab,articeTab,feedTab,weTab;      View[] tabs = new View[]{userTab,articeTab,feedTab,weTab};      @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                TabHost tabHost = getTabHost();          tabHost.setup();   //Call setup() before adding tabs if loading TabHost using findViewById().                     for(int i=0;i<tabs.length;i++){             Intent intent = new Intent(this,AActivity.class);            tabs[i] = (View) LayoutInflater.from(this).inflate(R.layout.tabmini, null);              ImageView text = (ImageView) tabs[i].findViewById(R.id.tab_label);                         tabHost.addTab(tabHost.newTabSpec(title[i]).setIndicator(tabs[i]).setContent(intent));             tabHost.setCurrentTab(1);        }      }}

TabHost里面的布局(tabmini.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="40dp"      android:paddingLeft="5dip"      android:paddingRight="5dip"      android:background="#ff0000">              <ImageView android:id="@+id/tab_label"            android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:layout_centerInParent="true"          android:gravity="center"          android:background="@drawable/btndown"        />   </RelativeLayout>

更多相关文章

  1. Android 弹出键盘向上顶布局
  2. ktolin在Android中布局界面拼接
  3. android之布局LinearLayout
  4. android之线性布局LinearLayout以及weight权重使用
  5. 【Android】使用代码动态创建布局
  6. Android Studio 自带的侧滑布局设置
  7. android UI布局练习3
  8. android怎样在布局文件监听事假

随机推荐

  1. MySQL启动报错问题InnoDB:Unable to lock
  2. 记一次MySQL Slave库恢复实战记录
  3. MySQL8.0 DDL原子性特性及实现原理
  4. 在Windows环境下安装MySQL 的教程图解
  5. 简单了解mysql mycat 中间件
  6. mysql如何在已有数据库上统一字符集
  7. 简单了解添加mysql索引的3条原则
  8. 简单了解操作mysql数据库的命令行神器myc
  9. MySQL分表和分区的具体实现方法
  10. mysql 5.7.17 winx64解压版安装配置方法