[color=blue][b](1)自定义Tab[/b][/color]
通过tabHost的indicator来设置自己特殊的布局。
public class MainActivity extends TabActivity {

TabHost tabHost;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

tabHost = getTabHost();
setTabs();
tabHost.setCurrentTab(0);
}

private void setTabs() {
addTab("Home", R.drawable.tab_home, HomeActivity.class);
addTab("Chat", R.drawable.tab_chat, ChatActivity.class);
}

private void addTab(String labelId, int drawableId, Class<?> c) {
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);

spec.setIndicator(tabIndicator);
spec.setContent(new Intent(this, c));
tabHost.addTab(spec);
}

}


[b]主页面 res/layout/main.xml[/b]
放在的下边,让Tab导航处于屏幕底部
 ... >










[b]Tab布局 res/layout/tab_indicator.xml[/b]
      :
>
      :
/>
      :
android:textColor="@color/tab_text" <-- ③
/>


[b]每个Tab的图标 res/drawable/tab_home.xml[/b]





[b]Tab文字色 res/color/tab_text.xml[/b]





[color=blue][b](2)做一个中间凸起的Tab[/b][/color]

[b]主页面 res/layout/main.xml[/b]
TabHost的下边添加
    android:id="@+id/ibHome"
android:layout_width="70sp"
android:layout_height="70sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@null"
android:src="@drawable/camera" />


[b]MainActivity.java[/b]
ImageButton ib = (ImageButton) findViewById(R.id.ibHome);
ib.setOnClickListener(new OnClickListener() {
//...
});


[b]在所有的Tab中间添加一个虚拟的Tab[/b]
addTab("", R.drawable.tab_home, HomeActivity.class);


[b]最终效果图:[/b]
[img]http://dl2.iteye.com/upload/attachment/0107/2344/505f5193-e880-3e59-8ba7-db2cdb5e70eb.png[/img]

更多相关文章

  1. 阅读《Android(安卓)从入门到精通》(25)——标签切换
  2. android实现计算器功能
  3. 【Android(安卓)Studio】LinearLayout(线性布局)的相关属性
  4. android checkbox多选框实现
  5. Android(安卓)之 自定义控件用法介绍
  6. 安卓布局详解
  7. Android中常用方法的归纳集合总结(二)
  8. 【Android】FragmentTabHost实现问题记录
  9. android搜索热词(热门标签)流式布局的实现

随机推荐

  1. Android(安卓)python环境搭建
  2. android 界面跳转
  3. 利用ActivityInstrumentationTestCase2测
  4. 【android studio】 the logging tag can
  5. JNI / C for android 技术总揽
  6. Android中检测手机制式和移动网络类型
  7. Android中的数据存储与传输
  8. 在 Android 中使用 SQLite, ContentProvi
  9. [Android] Activity页面切换效果
  10. 如何提高Android用户体验