Android UI中间凸起的Tab(Raised Center Tabbar)

[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]

你可能感兴趣的:(Android)