这是前段时间做的一个项目的一部分,我把它单独提取出来!效果如下图:
可以把选项卡放在一个Activity的任何位置,自定义了选项卡按钮的背景颜色!
basicview_tab.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#852741"
>
<!-- 导入别的xml文件 -->
<include layout="@layout/title_bar"/>
<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:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
自定义选项卡按钮 TabButton
public class TabButton extends LinearLayout {
public TabButton(Context c, int drawable, String text) {
super(c);
LayoutInflater inflater = LayoutInflater.from(c);
View view = inflater.inflate(R.layout.tab_button_layout, null);
addView(view);
TextView tv = (TextView) view.findViewById(R.id.tab_button_text);
ImageView iv = (ImageView) view.findViewById(R.id.tab_button_img);
iv.setImageResource(drawable);
tv.setText(text);
}
}
布局 tab_button_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="62dip"
android:background="@drawable/tab_selector_bg"
android:gravity="center"
>
<ImageView
android:layout_width="240dip"
android:layout_height="wrap_content"
android:id="@+id/tab_button_img"
android:layout_gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tab_button_text"
android:layout_gravity="center"
android:textColor="#ffffff"
/>
</LinearLayout>
主界面代码 BasicViewTab
public class BasicViewTab extends TabActivity {
private TabHost tabHost;
private TextView textView;
/* (non-Javadoc)
* @see android.app.ActivityGroup#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.basicview_tab);
Intent intent = new Intent(BasicViewTab.this,TabExpenses.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
textView = (TextView)findViewById(R.id.tv_title_bar);
textView.setText("Basic View Factor");
tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator(new TabButton(this,
R.drawable.tabbar_icon_basic_expenses_selector,
"Expenses"))
.setContent(intent));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator(new TabButton(this,
R.drawable.tabbar_icon_basic_setting_selector,
"Setting"))
.setContent(new Intent(this, TabSetting.class)));
tabHost.setCurrentTab(0);
ImageView backHome = (ImageView) findViewById(R.id.btn_back_home);
backHome.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
BasicViewTab.this.finish();
}
});
}
}
附件里有完整代码!
分享到:
相关推荐
android 自定义中间带圆形按钮的底部导航控件.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
一个比较美观的圆角Tab选项卡切换效果.html一个比较美观的圆角Tab选项卡切换效果.html一个比较美观的圆角Tab选项卡切换效果.html
安卓源码包 UI布局 textView SQLSEVER&安卓 Tab选项卡Android例子源码 33个合集: [四次元]Android ViewPager Fragment实现选项卡.rar [四次元]Android 操作数据库实例.zip [四次元]android 通过jdts.jar 连接SQL...
非常适合按钮、徽标和导航/标签栏。易于扩展、设计和集成到项目中。
在窄屏设备上运行时,它使用拆分操作栏,并显示三个选项卡。介绍此示例展示了如何在使用自定义主题的运行 Android v2.1+ 的设备上使用ActionBar 的样式。 此 Activity 扩展自 ActionBarActivity,后者提供在运行 ...
Android材质导航(工具栏,导航抽屉,导航视图,选项卡,CardView,ViewPager) 物料导航的组成部分: 支持Android API 8+ 工具栏 导航抽屉(带有指示器动画) 导航视图 动态标签(自定义的Google SlidingTab / ...
仿Chrome浏览器风格可单独关闭的网页TAB选项卡插件,可以依次打开多个TAB,每个TAB上都有关闭按钮,可以单独被关闭,美化的也很漂亮,功能更人性化的网页选项卡插件,自带的示例运行于HTML5环境,各个功能都可充分...
实现自义定按钮,按下的状态和松开的状态;GridView宫格效果的实现;实现抽屉的效果!
1.5.6 Android媒体和电话组件 1.5.7 Android Java包 1.6 利用Android源代码 1.7 本书的示例项目 1.8 小结 第2章 设置开发环境 2.1 设置环境 2.1.1 下载JDK 6 2.1.2 下载Eclipse 3.6 ...
7.1.6 选项卡 134 7.2 LinearLayout 138 7.3 RelativeLayout 139 7.4 AbsoluteLayout 141 7.5 TableLayout 143 7.6 布局嵌套 146 7.7 屏幕旋转 152 本章小结 154 第8章 多线程 155 8.1 多线程案例--计时器 ...
2.4.7 选项卡(TabHost)的功能和 用法 93 2.4.8 滚动视图(ScrollView)的 功能和用法 95 2.4.9 列表视图(ListView和 ListActivity) 95 2.4.10 可展开的列表组件(ExpandableListView) 101 ...
有四个选项卡。 前两天导师要求做一个给本科学生预定机房座位的app,出发点来自这里。做着做着遇到很多问题,都解决了。这个效果感觉还不错,整理一下。 MainActivity package com.example.fragmentmytest; import...
� GPS 卫星导航功能,手机照相, MP3 ,蓝芽等均被列为 Android 所提供支持的基本选项。 � Android 的平台基本上是免费的,虽然有部份原生链接库会要求费用,但大部份是免权利金; Android 的 程序可以采用 JAVA ...
1.5.6 Android媒体和电话组件 1.5.7 Android Java包 1.6 利用Android源代码 1.7 本书的示例项目 1.8 小结 第2章 设置开发环境 2.1 设置环境 2.1.1 下载JDK 6 2.1.2 下载Eclipse 3.6 ...
全书共分11章,主要以范例集的方式来讲述android的知识点,详细介绍了开发android的人机交互界面、android常用的开发控件、android手机收发短信等通信服务、开发android手机的自动服务功能和娱乐多媒体功能以及...
全书共分11章,主要以范例集的方式来讲述Android的知识点,详细介绍了开发Android的人机交互界面、Android常用的开发控件、Android手机收发短信等通信服务、开发Android手机的自动服务功能和娱乐多媒体功能以及整合...
NguiLib English || 适用于Android的美观,实用,易用的自定义视图和布局集合,minSdkVersion> = 14... 腾讯QQ选项卡按钮动画效果的完美实现信息: 2.EcgView。 心电图显示信息: 3.PolygonLoadView。 冷负载视图灵感:
这可能是我在Android上最喜欢的导航模式,但愿它在iOS上更常见! 这是React Native的非常简单的纯JavaScript实现。 有关此动画背后的工作原理的更多信息,请查看《 反弹”部分。 将其添加到您的项目 运行npm ...