Android(安卓)UI中间凸起的Tab(Raised Center Tabbar)
16lz
2021-01-24
[color=blue][b](1)自定义Tab[/b][/color]
通过tabHost的indicator来设置自己特殊的布局。
[b]主页面 res/layout/main.xml[/b]
把放在的下边,让Tab导航处于屏幕底部
[b]Tab布局 res/layout/tab_indicator.xml[/b]
[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的下边添加
[b]MainActivity.java[/b]
[b]在所有的Tab中间添加一个虚拟的Tab[/b]
[b]最终效果图:[/b]
[img]http://dl2.iteye.com/upload/attachment/0107/2344/505f5193-e880-3e59-8ba7-db2cdb5e70eb.png[/img]
通过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]
把
... >
[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(安卓)从入门到精通》(25)——标签切换
- android实现计算器功能
- 【Android(安卓)Studio】LinearLayout(线性布局)的相关属性
- android checkbox多选框实现
- Android(安卓)之 自定义控件用法介绍
- 安卓布局详解
- Android中常用方法的归纳集合总结(二)
- 【Android】FragmentTabHost实现问题记录
- android搜索热词(热门标签)流式布局的实现