(1)自定义Tab
通过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);
}
}
主页面 res/layout/main.xml
把<TabWidget>放在<FrameLayout>的下边,让Tab导航处于屏幕底部
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
... >
<TabHost android:id="@android:id/tabhost" .. >
<LinearLayout .. >
<!-- 主体内容部分 -->
<FrameLayout android:id="@android:id/tabcontent" .. />
<!-- Tab导航部分 -->
<TabWidget android:id="@android:id/tabs" .. />
</LinearLayout>
</TabHost>
</RelativeLayout>
Tab布局 res/layout/tab_indicator.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
:
>
<ImageView android:id="@+id/icon" <-- ①
:
/>
<TextView android:id="@+id/title" <-- ②
:
android:textColor="@color/tab_text" <-- ③
/>
</RelativeLayout>
每个Tab的图标 res/drawable/tab_home.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:drawable="@drawable/home_normal"/>
<item android:state_selected="true" android:drawable="@drawable/home_selected" />
</selector>
Tab文字色 res/color/tab_text.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:color="#f888" />
<item android:state_selected="true" android:color="#ffff" />
</selector>
(2)做一个中间凸起的Tab
主页面 res/layout/main.xml
TabHost的下边添加
<ImageButton
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" />
MainActivity.java
ImageButton ib = (ImageButton) findViewById(R.id.ibHome);
ib.setOnClickListener(new OnClickListener() {
//...
});
在所有的Tab中间添加一个虚拟的Tab
addTab("", R.drawable.tab_home, HomeActivity.class);
最终效果图:
- 大小: 16.2 KB
分享到:
相关推荐
Raised Center Tab介绍: ...自定义TabHost外观,使中间的tab相对其他tab突起(所谓的Raised Center Tab)。 测试环境: Eclipse 4.2, Android 3.0 以上。 注意:测试环境并不代表适用环境。
Raised Center Tab介绍: 自定义TabHost外观,使中间的tab相对其他tab突起(所谓的Raised Center Tab)。
自定义UITabBar。自定义中间突起形式的Tab Bar样式,类似的UI在Instagram,Path等应用中可见。支持转屏。 注意:请在Mac下解压使用
来源:Licence:MIT平台:iOS设备:iPhone / iPad作者:Peter Boctor ...自定义中间突起形式的Tab Bar样式,类似的UI在Instagram,Path等应用中可见。支持转屏。 Code4App编译测试,适用环境:Xcode 4.3, iOS 5.0。
weifenluo.winformsui.docking 2.9(最新源码&例子) 1. Add an event to the DockPanel that will be raised when the value of the AutoHideWindow's ActiveContent property changes. 2. Opt-in ...
可自定义TabHost外观效果,源码Raised Center Tab,可以支持自定义TabHost外观,使中间的tab相对其他tab突起,也就是所谓的Raised Center Tab的了,大家可以了解一下先,喜欢的朋友可以收藏起来吧。 This ...
Written by real world Android developers, this book addresses the trickiest questions raised in forums and mailing lists. Using an easy-to-follow problem/solution/discussion format, it dives into ...
Analysis and evaluation of square root raised cosine
By viewing the application's UI hierarchical structure, property values, and raised events, developers and testers can verify that the UI they are creating is programmatically accessible to assistive...
Roberta Raised
By viewing the application's UI hierarchical structure, property values, and raised events, developers and testers can verify that the UI they are creating is programmatically accessible to assistive...
with_raised_flag: 如何联系我: SwiftUISwiftUI下拉SwiftUI中的条形图自定义切换按钮菜单按钮 卡应用 捐款如果您喜欢这个项目并希望支持我,则可以通过帮助我获得一品脱来实现。 ;) 学分:copyright:Arvind Patel |...
import javax.swing.BorderFactory; import javax.swing.JPanel;... cabinetView.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); } public JPanel getView(){ return cabinetView; } }
RubberStamp:closed_mailbox_with_raised_flag:RubberStamp是一个Android库,可让您轻松为图像加水印。 功能在图像上添加水印。 它可以是文本或其他图像。 多种方式和功能RubberStamp:closed_mailbox_with_raised_...
InAppUpdater Android库可轻松实现应用程序内更新:pencil:使用步骤1:将其添加到根build.gradle allprojects {存储库{maven {url“ https:// jitpack。InAppUpdater Android库可轻松实现应用内更新:pencil:使用步骤...
利用深度学习框架进行手势识别,可识别多种手势,使用python语言
S.J(2009)___Non-Data-Aided Symbol Timing-Error Detection比较the Raised-Cosine and Better Than Raised-Cosine两种的性能
square root raised cosine impulse response