资源准备
下载一个微信apk,解压,并找出所需的资源图片。
layout中XML布局
<?xml version="1.0" encoding="UTF-8"?>
<!-- Tab导航 最新版 -->
<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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF" >
</FrameLayout>
<!-- TabWidget管理所有的选项卡,id名是android指定的 -->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
<!-- Frame下放置单选群组替代TAB效果 -->
<RadioGroup
android:id="@+id/main_radio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ccc"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<RadioButton
android:id="@+id/tab_icon_weixin"
style="@style/main_tab_bottom"
android:checked="true"
android:drawableTop="@drawable/tab_weixin_normal"
android:text="微信" />
<RadioButton
android:id="@+id/tab_icon_address"
style="@style/main_tab_bottom"
android:checked="false"
android:drawableTop="@drawable/tab_address_normal"
android:text="通讯录" />
<RadioButton
android:id="@+id/tab_icon_find"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/tab_find_frd_normal"
android:text="发现" />
<RadioButton
android:id="@+id/tab_icon_myself"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/tab_settings_normal"
android:text="我" />
</RadioGroup>
</RelativeLayout>
</TabHost>
style中XML文档
<!-- MainTab选项卡中单选按钮的样式,其中包括了文本、selector、padding、宽高、权重等的设置 -->
<style name="main_tab_bottom">
<item name="android:textSize">13sp</item>
<item name="android:textColor">#666666</item>
<item name="android:gravity">center_horizontal</item>
<!-- 该处引用drawable下面的一个xml文档(selector) -->
<item name="android:paddingTop">5dp</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1.0</item>
<!-- 每个按钮的权重,相等则平分尺寸 -->
<item name="android:button">@null</item>
<!-- 隐藏单选按钮 -->
<item name="android:layout_marginTop">1.0dip</item>
<item name="android:paddingBottom">5.0dip</item>
</style>
Activity中Java文件
package com.app;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TabWidget;
/**
* Tab导航
*/
//public class Tabs extends TabActivity implements View.OnClickListener{
public class Tabs extends TabActivity{
public static TabHost mTabHost;
public static TabHost getmTabHost() {
return mTabHost;
}
private RadioGroup main_radio;
private RadioButton tab_icon_weixin, tab_icon_address, tab_icon_find,tab_icon_myself;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
mTabHost = getTabHost();
final TabWidget tabWidget = mTabHost.getTabWidget();
tabWidget.setStripEnabled(false);// 圆角边线不启用
//添加n个tab选项卡,定义他们的tab名,指示名,目标屏对应的类
mTabHost.addTab(mTabHost.newTabSpec("TAG1").setIndicator("0").setContent(new Intent(this, WeixinActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("TAG2").setIndicator("1").setContent(new Intent(this, AddressActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("TAG3").setIndicator("2").setContent(new Intent(this, FindActivity.class)));
mTabHost.addTab(mTabHost.newTabSpec("TAG4").setIndicator("3").setContent(new Intent(this, MyselfActivity.class)));
// 视觉上,用单选按钮替代TabWidget
main_radio = (RadioGroup) findViewById(R.id.main_radio);
tab_icon_weixin = (RadioButton) findViewById(R.id.tab_icon_weixin);
tab_icon_address = (RadioButton) findViewById(R.id.tab_icon_address);
tab_icon_find = (RadioButton) findViewById(R.id.tab_icon_find);
tab_icon_myself = (RadioButton) findViewById(R.id.tab_icon_myself);
main_radio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int id) {
if (id == tab_icon_weixin.getId()) {
mTabHost.setCurrentTab(0);
} else if (id == tab_icon_address.getId()) {
mTabHost.setCurrentTab(1);
} else if (id == tab_icon_find.getId()) {
mTabHost.setCurrentTab(2);
} else if (id == tab_icon_myself.getId()) {
mTabHost.setCurrentTab(3);
}
}
});
// 设置当前显示哪一个标签
mTabHost.setCurrentTab(0);
// 遍历tabWidget每个标签,设置背景图片 无
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View vv = tabWidget.getChildAt(i);
vv.getLayoutParams().height = 45;
// vv.getLayoutParams().width = 65;
vv.setBackgroundDrawable(null);
}
// findViewById(R.id.tab_icon_brand).setOnClickListener(this);
}
}
效果图
分享到:
相关推荐
ImageView 圆环旋转+仿微信底部TabHost+fragment
很长一段时间没有上传资源了,最近觉得微信的主界面滑动很好用,研究了下,秉着开源精神,这里把资源公布出来,供大家免费下载。 主要有 TabHost + Fragment 来实现。 当然,另一种实现方式是 ViewGroup + ViewPager...
android仿微信底部选项卡(可滑动),里面的例子有两个,一个是仿微信点击可以切换选项卡,一个是用viewpager实现可滑动和切换的底部选项卡。
配套博客 http://blog.csdn.net/shulianghan/article/details/18233209 对TabHost选项卡组件进行了详细解析.
android TabHost 底部显示 实现了底部显示选项卡
实现主流界面的选项卡布局。 这里新建3个的Intent用于Activity的切换 Intent tab1 = new Intent(this, TabOneActivity.class); Intent tab2 = new Intent(this, TabTwoActivity.class); Intent tab3 = new Intent...
android 自定义实现TAB, 简化开发代码,提供效率
一个使用FragmentTabHost搭建的仿微信界面Demo,方便以后复习使用
TabHost选项卡
仿微信TabHost.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
很实用的东西,目前很多app都有用到,利用Tabhost做底部选项卡,利用fragment+viewpage实现滑动效果
此项目中总结了Android开发实战项目中常要用到的选项卡功能块
仿微信例子,使用TabHost实现底部tab,可以显示未读信息条数。适合初学者学习研究。
本文档用于解决更改安卓组件中的tabhost的选项卡背景图片的问题
1、底部tabhost嵌套顶部tabhost. 2、顶部tabhost,嵌套listview。 3、顶部tabhost子tab选项仿网易新闻功能,可以滑动,每一个对应一个listvie
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
通过Fragment+TabHost实现底部选项卡
Android_TabHost_TabWidget选项卡总结
案例十五tabhost选项卡菜单的使用
Android实现tabHost控件自定义页签页面源码