- 浏览: 3579190 次
- 性别:
- 来自: 杭州
-
文章分类
- 全部博客 (1491)
- Hibernate (28)
- spring (37)
- struts2 (19)
- jsp (12)
- servlet (2)
- mysql (24)
- tomcat (3)
- weblogic (1)
- ajax (36)
- jquery (47)
- html (43)
- JS (32)
- ibatis (0)
- DWR (3)
- EXTJS (43)
- Linux (15)
- Maven (3)
- python (8)
- 其他 (8)
- JAVASE (6)
- java javase string (0)
- JAVA 语法 (3)
- juddiv3 (15)
- Mule (1)
- jquery easyui (2)
- mule esb (1)
- java (644)
- log4j (4)
- weka (12)
- android (257)
- web services (4)
- PHP (1)
- 算法 (18)
- 数据结构 算法 (7)
- 数据挖掘 (4)
- 期刊 (6)
- 面试 (5)
- C++ (1)
- 论文 (10)
- 工作 (1)
- 数据结构 (6)
- JAVA配置 (1)
- JAVA垃圾回收 (2)
- SVM (13)
- web st (1)
- jvm (7)
- weka libsvm (1)
- weka屈伟 (1)
- job (2)
- 排序 算法 面试 (3)
- spss (2)
- 搜索引擎 (6)
- java 爬虫 (6)
- 分布式 (1)
- data ming (1)
- eclipse (6)
- 正则表达式 (1)
- 分词器 (2)
- 张孝祥 (1)
- solr (3)
- nutch (1)
- 爬虫 (4)
- lucene (3)
- 狗日的腾讯 (1)
- 我的收藏网址 (13)
- 网络 (1)
- java 数据结构 (22)
- ACM (7)
- jboss (0)
- 大纸 (10)
- maven2 (0)
- elipse (0)
- SVN使用 (2)
- office (1)
- .net (14)
- extjs4 (2)
- zhaopin (0)
- C (2)
- spring mvc (5)
- JPA (9)
- iphone (3)
- css (3)
- 前端框架 (2)
- jui (1)
- dwz (1)
- joomla (1)
- im (1)
- web (2)
- 1 (0)
- 移动UI (1)
- java (1)
- jsoup (1)
- 管理模板 (2)
- javajava (1)
- kali (7)
- 单片机 (1)
- 嵌入式 (1)
- mybatis (2)
- layui (7)
- asp (12)
- asp.net (1)
- sql (1)
- c# (4)
- andorid (1)
- 地价 (1)
- yihuo (1)
- oracle (1)
最新评论
-
endual:
https://blog.csdn.net/chenxbxh2 ...
IE6 bug -
ice86rain:
你好,ES跑起来了吗?我的在tomcat启动时卡在这里Hibe ...
ES架构技术介绍 -
TopLongMan:
...
java public ,protect,friendly,private的方法权限(转) -
贝塔ZQ:
java实现操作word中的表格内容,用插件实现的话,可以试试 ...
java 读取 doc poi读取word中的表格(转) -
ysj570440569:
Maven多模块spring + springMVC + JP ...
Spring+SpringMVC+JPA

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://mmqzlj.blog.51cto.com/2092359/642465
android项目中碰到需要替换tabHost默认样式的情况,需要达到下图的效果:

为了做成这样的效果,花了些时间,这里做个笔记,给有需要的朋友。
步骤一:新建一个xml布局文件,命名main.xml
步骤二:在Activity中添加我们的tab
代码如下
步骤三:在createTabView方法中,我们载入了布局文件tab_indicator.xml,改布局很简单,就是放置一个带背景的布局,在布局中放一个textView用于显示tab标题,以下为该布局文件内容
步骤四:在上面的布局文件中我们把该布局的背景定义为chat_tab_selector,这里同样需要在drawable文件夹下新建chat_tab_selector.xml,内容很简单,就是做一个按下时的背景切换,内容如下:
里面做了两张图进行状态切换,这两张图同样放drawable下就可以了
至此,自定义tab的步骤就完成了。如果要做成更复杂的样式,大家可以在此基础上进行扩展。

为了做成这样的效果,花了些时间,这里做个笔记,给有需要的朋友。
步骤一:新建一个xml布局文件,命名main.xml
<?xml version="1.0" encoding="utf-8"?>
<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" android:background="@color/white">
<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"
android:gravity="center_horizontal|center_vertical"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
<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" android:background="@color/white">
<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"
android:gravity="center_horizontal|center_vertical"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
步骤二:在Activity中添加我们的tab
代码如下
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
Intent intent1 = new Intent(this,OfficialActivity.class);
createTab("公共聊天室",intent1);
Intent intent2 = new Intent(this, NearByActivity.class);
createTab("周边",intent2);
Intent intent3= new Intent(this, HistoryActivity.class);
createTab("历史",intent3);
mTabHost.setCurrentTab(1);
}
private void createTab(String text ,Intent intent){ mTabHost.addTab(mTabHost.newTabSpec(text).setIndicator(createTabView(text)).setContent(intent));
}
private View createTabView(String text) {
View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null);
TextView tv = (TextView) view.findViewById(R.id.tv_tab);
tv.setText(text);
return view;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
Intent intent1 = new Intent(this,OfficialActivity.class);
createTab("公共聊天室",intent1);
Intent intent2 = new Intent(this, NearByActivity.class);
createTab("周边",intent2);
Intent intent3= new Intent(this, HistoryActivity.class);
createTab("历史",intent3);
mTabHost.setCurrentTab(1);
}
private void createTab(String text ,Intent intent){ mTabHost.addTab(mTabHost.newTabSpec(text).setIndicator(createTabView(text)).setContent(intent));
}
private View createTabView(String text) {
View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null);
TextView tv = (TextView) view.findViewById(R.id.tv_tab);
tv.setText(text);
return view;
}
步骤三:在createTabView方法中,我们载入了布局文件tab_indicator.xml,改布局很简单,就是放置一个带背景的布局,在布局中放一个textView用于显示tab标题,以下为该布局文件内容
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:gravity="center"
android:theme="@android:style/Theme.NoTitleBar" android:background="@drawable/chat_tab_selector">
<TextView android:id="@+id/tv_tab" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="tab1" android:textColor="@color/white"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="vertical" android:gravity="center"
android:theme="@android:style/Theme.NoTitleBar" android:background="@drawable/chat_tab_selector">
<TextView android:id="@+id/tv_tab" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="tab1" android:textColor="@color/white"/>
</LinearLayout>
步骤四:在上面的布局文件中我们把该布局的背景定义为chat_tab_selector,这里同样需要在drawable文件夹下新建chat_tab_selector.xml,内容很简单,就是做一个按下时的背景切换,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android = "http://schemas.android.com/apk/res/android">
<item
android:state_focused = "true"
android:drawable = "@drawable/topbar_bg_down"
/>
<item
android:state_selected = "true"
android:drawable = "@drawable/topbar_bg_down"
/>
<item
android:state_pressed = "true"
android:drawable = "@drawable/topbar_bg_down"
/>
<item android:drawable = "@drawable/topbar_background" />
</selector>
<selector xmlns:android = "http://schemas.android.com/apk/res/android">
<item
android:state_focused = "true"
android:drawable = "@drawable/topbar_bg_down"
/>
<item
android:state_selected = "true"
android:drawable = "@drawable/topbar_bg_down"
/>
<item
android:state_pressed = "true"
android:drawable = "@drawable/topbar_bg_down"
/>
<item android:drawable = "@drawable/topbar_background" />
</selector>
里面做了两张图进行状态切换,这两张图同样放drawable下就可以了
至此,自定义tab的步骤就完成了。如果要做成更复杂的样式,大家可以在此基础上进行扩展。
本文出自 “我的JAVA之路” 博客,请务必保留此出处http://mmqzlj.blog.51cto.com/2092359/642465
发表评论
-
android离线
2019-11-04 21:25 304https://www.jianshu.com/p/fdfc4 ... -
android 异步更新
2015-07-11 22:42 1509http://www.apkbus.com/forum.php ... -
仿微米
2015-06-26 10:22 0http://www.javaapk.com/source/4 ... -
仿微信
2015-06-26 10:21 1924http://www.javaapk.com/source/1 ... -
网易客户端
2015-06-26 10:20 1612http://www.javaapk.com/source/4 ... -
仿朋友圈
2015-06-26 10:18 1706http://www.javaapk.com/source/8 ... -
仿朋友圈
2015-06-26 10:13 1844http://www.eoeandroid.com/threa ... -
全国ABC查询
2015-06-26 10:07 1382IM 功能 环信云 信息统计 Umeng 分享Umeng 更新 ... -
android 判断网络
2015-06-25 16:00 1273http://www.cnblogs.com/renqingp ... -
android 多彩表格
2015-05-31 16:06 1483http://blog.csdn.net/conowen/ar ... -
android socket
2015-05-31 16:01 1652http://blog.csdn.net/conowen/ar ... -
微信播放语音3
2015-02-25 12:00 1440http://download.csdn.net/detail ... -
微信语音播放2
2015-02-25 11:57 1371http://download.csdn.net/detail ... -
微信语音播放
2015-02-25 11:56 1721http://www.apkbus.com/android-1 ... -
超强的资料整合
2015-01-05 11:04 1229http://zz563143188.iteye.com/bl ... -
最强开发资源平台大合集
2015-01-04 14:50 1893程序员代码应用开发平 ... -
Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
2014-09-04 15:45 1388http://blog.csdn.net/vipzjyno1/ ... -
android应用推广
2014-09-03 23:25 1321应用推广不必愁,有米 ... -
android 图片异步加载
2014-09-03 16:47 1139http://www.csdn.net/article/201 ... -
android hander的使用
2014-09-02 23:46 1368http://www.cnblogs.com/xiaoran1 ...
相关推荐
Android Tablayout 自定义Tab布局的使用案例 Android Tablayout 是 Android 设计库中的一部分,主要用于实现标签页功能。Tablayout 中的 Tab 可以自定义布局,以满足不同的需求。本文将 introduction 了 Android ...
在Android中,自定义Tab页的外观通常涉及到修改Tab的布局和样式。我们可以创建一个XML布局文件,用于定义每个RadioButton的外观。例如,创建一个名为`custom_tab.xml`的文件,包含RadioButton的文本、图标以及所需的...
你可以创建一个`LinearLayout`或`RelativeLayout`,并添加需要的控件(如`TextView`、`ImageView`等)来实现自定义的tab样式。 ```java TabLayout tabLayout = findViewById(R.id.tab_layout); TabLayout.Tab tab =...
本篇文章将深入探讨如何在Android中实现自定义的底部TAB,以满足个性化需求。 首先,我们需要理解Android的UI组件系统。在Android中,底部导航栏通常由`BottomNavigationView`或自定义视图来实现。对于自定义底部...
2. **实现自定义View**:在Android中,可以创建一个新的Java或Kotlin类继承自`View`或`ViewGroup`,如`LinearLayout`或`RelativeLayout`,然后重写其`onDraw()`方法以绘制自定义的Tab。或者,你可以使用`...
可通过自定义属性设置选项卡样式,且Tab的数目也可通过属性灵活设置,可设置为文本选项卡或图片选项卡,利用回调监听响应各Tab的点击事件,且设置方法和android原生控件设置点击监听的方法基本一致。
本文将深入探讨如何自定义Android的TabHost控件样式。 首先,我们从基础开始。TabHost是Android提供的一个布局容器,它包含一个TabWidget(显示各个Tab)和一个FrameLayout(用于显示被选中的Tab的内容)。默认的...
通过以上步骤,我们已经成功地自定义了Android的TabHost样式。这不仅可以提升应用的视觉效果,还可以提高用户的交互体验。记得在实际项目中,要根据需求灵活调整样式和逻辑,以达到最佳的效果。同时,阅读博客中的...
`TabLayout`提供了添加Tab、自定义Tab样式以及与`ViewPager`联动的功能,而`ViewPager`则负责管理多个可滑动的页面内容。 2. **居中滚动**: 实现Tab居中滚动的关键在于监听`TabLayout`的滑动事件,并根据当前选中...
为了实现不同tab有不同的标题显示样式,我们可以在`setTitle()`方法中传入自定义的字符串资源,或者使用自定义的标题视图。例如,我们可以创建一个自定义的`Toolbar`并设置其标题: ```xml <androidx.appcompat....
此外,这种竖直选项卡还支持自定义tab样式,这对于品牌识别和用户体验的提升非常有帮助。开发者可以通过设置颜色、字体、图标等属性,使选项卡与应用的整体风格保持一致,提高用户的视觉舒适度和操作满意度。 自带...
总之,"Android Tab实现源码"中的"RaisedCenterTab"是一种高级的自定义Tab实现,它融合了自定义View、触摸反馈、动画效果、适配器、Fragment管理等多个Android开发关键知识点。通过深入研究这个源码,开发者不仅可以...
6. **字体与颜色**:自定义RadioButton的字体大小、颜色,以及选中和未选中时的文字样式,可以使用android:textSize、android:textColor等属性,或者在主题中全局设定。 在TestDemo项目中,你可以找到一个实际的...
在Android开发中,Tab页面是...不过,实际项目中可能需要更复杂的定制,例如添加滑动指示器、自定义Tab样式等,这就需要进一步学习和实践Android的UI定制技巧。希望这个入门示例能为你的Android Tab页面开发提供帮助。
这个源码很可能是使用了`TabLayout`,这是Android Design Support Library提供的组件,它提供了Material Design风格的Tab设计,易于使用且样式美观。 `TabLayout`通常与`ViewPager`结合使用,`ViewPager`用于滑动...
总的来说,"android Tab 在右侧"是一种非标准但可行的界面设计,通过自定义布局和使用适当的组件,开发者可以在Android应用中实现这一功能。理解并掌握如何操作TabHost、TabLayout以及与其配合的组件,是实现这一...
6. **个性化Tab**:如果你需要更复杂的Tab样式,例如自定义图标或文字颜色,可以重写`TabLayout`的`Tab`对象,使用`setIcon`和`setText`方法,或者设置自定义的`TabView`。 7. **注意事项**:确保在不同的设备和...
5. **自定义Tab布局**: 有时我们可能需要自定义Tab的显示样式,比如设置文字和图标。这可以通过重写TabLayout的TabView或者使用CustomTabLayout实现。 6. **事件监听**: 为了响应用户的Tab切换操作,需要为...
5. **自定义Tab样式** 可以通过`TabLayout.OnTabSelectedListener`监听Tab选中状态,或者自定义`TabLayout.Tab`的视图,以实现个性化标签样式。 6. **源码解析** 了解`Menu`和`TabLayout`的内部工作原理,可以...
1. **自定义Tab样式** - 图片+文字:为了实现这种样式,我们需要创建一个自定义的View,包含ImageView和TextView,然后在TabLayout的Tab中使用这个自定义View。在Adapter中,我们可以通过`TabLayout.Tab....