android自定义TabWidget样式
先看看效果图吧,个人觉得图标丑了点,不过还行,自己用PS做的
下面是全部代码和流程,一定要按流程顺序来,不然错误!
1.tabhost.xml
- <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@android:id/tabhost"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <RelativeLayout
- android:id="@+id/relativelayout"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <LinearLayout
- android:id="@+id/tab1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab3"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab4"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- <LinearLayout
- android:id="@+id/tab5"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- </LinearLayout>
- </FrameLayout>
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:background="@drawable/tabwidget_bj" >
- </TabWidget>
- </RelativeLayout>
- </TabHost>
2.tab_item_view.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical" >
- <ImageView
- android:id="@+id/imageview"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|top"
- android:padding="3dp" />
- <TextView
- android:id="@+id/textview"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal|bottom"
- android:textColor="#fff"
- android:textSize="13sp"
- style="bold"/>
- </LinearLayout>
3.样式选择器selector:tab_item_style.xml,新建文件夹drawable,然后将该xml文件放进去
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:drawable="@drawable/unpressed_bj" android:state_selected="false"/>
- <item android:drawable="@drawable/pressed_bj" android:state_selected="true"/>
- </selector>
4.java代码实现:MyTabHost.java
- package com.example.androidtabhost4;
- import android.os.Bundle;
- import android.app.Activity;
- import android.app.TabActivity;
- import android.content.Intent;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.View;
- import android.widget.ImageView;
- import android.widget.TabHost;
- import android.widget.TextView;
- import android.widget.TabHost.TabSpec;
- public class MyTabHost extends TabActivity {
- private TabHost tabHost;
- private LayoutInflater layoutInflater;
- String[] mTitle = new String[] { "首页", "留言", "评论", "收藏", "更多" };
- int[] mIcon = new int[] { R.drawable.home, R.drawable.saying,
- R.drawable.zan, R.drawable.collect, R.drawable.more };
- int[] mTab = new int[] { R.id.tab1, R.id.tab2, R.id.tab3, R.id.tab4,
- R.id.tab5 };
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.tabhost);
- init();
- }
- public View getTabItemView(int i) {
- // TODO Auto-generated method stub
- View view = layoutInflater.inflate(R.layout.tab_item_view, null);
- ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
- imageView.setImageResource(mIcon[i]);
- TextView textView = (TextView) view.findViewById(R.id.textview);
- textView.setText(mTitle[i]);
- return view;
- }
- public void init() {
- // TODO Auto-generated method stub
- tabHost = getTabHost();
- layoutInflater = LayoutInflater.from(this);
- for (int i = 0; i < mTitle.length; i++) {
- TabSpec tabSpec = tabHost.newTabSpec(mTitle[i])
- .setIndicator(getTabItemView(i)).setContent(mTab[i]);
- tabHost.addTab(tabSpec);
- tabHost.getTabWidget().getChildAt(i)
- .setBackgroundResource(R.drawable.tab_item_style);
- tabHost.setup();
- }
- }
- }
android自定义TabWidget样式的更多相关文章
- Android: 自定义Tab样式,一种简单的方式。
之前看到过论坛里已经有人发过自定义Tab样式的帖子,感觉有些复杂了,这里分享个简单的方法. 1.制作4个9patch的tab样式,可参考android默认的资源 tab_unselected.9.pn ...
- Android 自定义title样式
requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性.参数是Window类中定义的常量.一.枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需 ...
- Android自定义ProgressBar样式
我们使用的进度条多种多样,下面有几种自定义的进度条的样式,下面介绍几个. 进度条的有基本的四种样式: 默认风格的进度条: android:progressBarStyle 水平长型进度条: andro ...
- android 自定义progressbar 样式
在res下创建drawable文件夹,新建文件drawable/progressbar_color.xml <layer-list xmlns:android="http://sche ...
- Android 自定义CheckBox 样式
新建Android XML文件,类型选Drawable,根结点选selector,在这定义具体的样式. <?xml version="1.0" encoding=" ...
- android自定义TabWidget
在做项目的时候,需要用到这个选项卡,刚开始看了系统的tabwidget,囧了,底边有黑线不说,还不美观,扒了好多的网页发现前辈做的能够满足自己的需求,将代码修改了下,就能用喽,伟人说过,站在前辈的肩膀 ...
- 转:android 自定义RadioButton样式
http://gundumw100.iteye.com/blog/1146527 上面这种3选1的效果如何做呢?用代码写? 其实有更简单的办法,忘了RadioButton有什么特性了吗? 我就用Ra ...
- Android 自定义CheckBox样式
1.首先在drawable文件夹中添加drawable文件checkbox_style.xml. <selector xmlns:android="http://schemas.and ...
- Android 自定义光标样式
今天自定义光标,自己切图,不过怎么切都是很宽.不是一个很细的条.我用ps花了一个像素的直线,放上去还是不行.后来在网上找到方法,那就是用shape.不得不说,shape真的是太吊了. 给EditTex ...
随机推荐
- Application Cache
轉發處:http://www.cnblogs.com/blackbird/archive/2012/06/12/2546751.html HTML5提供了一系列的特性来支持离线应用: applicat ...
- AI钻石风格logo教程
最终图像 与往常一样,这是我们要创建的最终图像: Step 1 按Ctrl+ N创建新文档.从单位下拉菜单中选择像素,在宽度和高度框中输入600,然后单击高级按钮.选择RGB,屏幕(72 PPI),并 ...
- 【转】 Linux Shell 命令--rename
重命名文件,经常用到mv命令,批量重命名文件rename是最好的选择,Linux的rename 命令有两个版本,一个是C语言版本的,一个是Perl语言版本的,判断方法:输入man rename 看到第 ...
- 55个高质量的Magento主题,助你构建电子商务站点
Magento是一个功能丰富的开源电子商务平台(译者注:基于PHP的Zend Framework开发),在网店的外观.商品管理以及其它功能上,它给商家提供了前所未有的灵活和易用性.通过挑选一个合适的M ...
- 王家林的“云计算分布式大数据Hadoop实战高手之路---从零开始”的第十一讲Hadoop图文训练课程:MapReduce的原理机制和流程图剖析
这一讲我们主要剖析MapReduce的原理机制和流程. “云计算分布式大数据Hadoop实战高手之路”之完整发布目录 云计算分布式大数据实战技术Hadoop交流群:312494188,每天都会在群中发 ...
- iOS 获取通讯录权限的时机
建议将获取通讯录权限的代码放到 -(void)viewDidAppear:(BOOL)animated 或 -(void)viewWillAppear:(BOOL)animated 假如放在 view ...
- openstack neutron网络主机节点网口配置 liberty版本之前的
- UVALive 3959 Rectangular Polygons (排序贪心)
Rectangular Polygons 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/G Description In thi ...
- CreateEvent的用法
事件对象就像一个开关:它只有两种状态---开和关.当一个事件处于”开”状态,我们称其为”有信号”否则称为”无信号”.可以在一个线程的执行函数中创建一个事件对象,然后观察它的状态,如果是”无信号”就让该 ...
- WPF中的DependencyProperty存储方式详解
前言 接触WPF有一段时间了,之前虽然也经常使用,但是对于DependencyProperty一直处于一知半解的状态.今天花了整整一下午将这个概念梳理了一下,自觉对这个概念有了较为清晰的认识,之前很多 ...