现在App基本的标配除了侧滑菜单,还有一个就是底部导航栏,常见的聊天工具QQ,微信,购物App都有底部导航栏,用户可以随便切换看不同的内容,说是情怀也好,用户体验也罢。我们开发的主要的还是讲的是如何如何实现其功能,网上实现的方式无外乎两种,一种是使用tabhost进行切换,一种是直接使用Fragment进行切换,底部导航栏的布局有的使用的是线性布局,有的是使用的RadioGroup,本文中是使用fragment+RadioGroup是实现的,看正文吧:

基础布局

其中主要低 底部导航栏,其他都没有什么,上面是一个Fragment自己替换一下即可,关于Fragment的使用可参考本人之前的博客;

activity_main.xml中的布局文件,由于样式比较多可以单独的放在style中的,鉴于方便查看,直接放在布局文件中,activity_main中的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="com.example.googlebottomfragment.MainActivity" > <FrameLayout
android:id="@+id/main_content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" /> <RadioGroup
android:id="@+id/tab_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/mmfooter_bg"
android:orientation="horizontal" > <RadioButton
android:id="@+id/rbChat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="@drawable/tab_selector_checked_bg"
android:button="@null"
android:checked="true"
android:drawableTop="@drawable/tab_selector_weixing"
android:gravity="center_horizontal|bottom"
android:paddingTop="2dp"
android:text="微信"
android:textColor="@color/tab_selector_tv_color" /> <RadioButton
android:id="@+id/rbAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="@drawable/tab_selector_checked_bg"
android:button="@null"
android:drawableTop="@drawable/tab_selector_tongxunlu"
android:gravity="center_horizontal|bottom"
android:paddingTop="2dp"
android:text="通讯录"
android:textColor="@color/tab_selector_tv_color" /> <RadioButton
android:id="@+id/rbFind"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="@drawable/tab_selector_checked_bg"
android:button="@null"
android:drawableTop="@drawable/tab_selector_faxian"
android:gravity="center_horizontal|bottom"
android:paddingTop="2dp"
android:text="发现"
android:textColor="@color/tab_selector_tv_color" /> <RadioButton
android:id="@+id/rbMe"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="@drawable/tab_selector_checked_bg"
android:button="@null"
android:drawableTop="@drawable/tab_selector_wo"
android:gravity="center_horizontal|bottom"
android:paddingTop="2dp"
android:text="我"
android:textColor="@color/tab_selector_tv_color" />
</RadioGroup> </LinearLayout>

 看下新建的布局和资源文件:

其中tab_selector_tv_color.xml主要是用于控制切换的时候显示下面字体的颜色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@android:color/white"/>
<item android:state_checked="false" android:color="@android:color/darker_gray"/>
<item android:color="@android:color/darker_gray"/> </selector>

  其中tab_selector_checked_bg.xml布局文件选中的时候每个RadioButtton的背景颜色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item
android:state_checked="true"
android:drawable="@drawable/tab_bg_halo"/> </selector>

其中tab_selector_weixing.xml主要是点击的时候显示不同的图片,一个是绿色的,一个是白色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false" android:drawable="@drawable/tab_weixin_normal"></item>
<item android:state_checked="true" android:drawable="@drawable/tab_weixin_pressed"></item> </selector>

  其中需要切换的chat.xml,address.xml,find.xml,me.xml都是一样的,其中chat.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="微信"
android:textSize="20sp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="http://www.cnblogs.com/xiaofeixiang"
android:textSize="15sp"
/> </LinearLayout>

 实现Demo

MainActivity.java中的代码,主要的就是设置一下OnCheckedChangeListener,注意MainActivity中需要继承FragmentActivity:

	public void initView() {
chat = new FragmentChat();
getSupportFragmentManager().beginTransaction().replace(R.id.main_content, chat).commit();
myTabRg = (RadioGroup) findViewById(R.id.tab_menu);
myTabRg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.rbChat:
chat = new FragmentChat();
getSupportFragmentManager().beginTransaction().replace(R.id.main_content, chat)
.commit();
break;
case R.id.rbAddress:
if (address==null) {
address =new FragmentAddress();
}
Log.i("MyFragment", "FragmentAddress");
getSupportFragmentManager().beginTransaction().replace(R.id.main_content, address).commit();
break;
case R.id.rbFind:
find = new FragmentFind();
getSupportFragmentManager().beginTransaction().replace(R.id.main_content, find)
.commit();
break;
case R.id.rbMe:
me = new FragmentMe();
getSupportFragmentManager().beginTransaction().replace(R.id.main_content, me)
.commit();
break;
default:
break;
} }
});

FragmentChat中的代码,其余的三个FragmentAddress,FragmentFind,FragmentMe类似,就不贴代码了,主要是继承Fragment 即可:

public class FragmentChat extends Fragment {

	@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
} @Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.chat, null);
} }

  最后看张通讯录的截图吧:

、-

如果有需要,推荐之后,评论区留下邮箱,一天之内会处理~

Android UI-仿微信底部导航栏布局的更多相关文章

  1. Android 高仿新浪微博底部导航栏,实现双击首页Tab,页面的ListView滚动、刷新

    现在很多APP,如微信.QQ.微博等等,它们的主页面都无一例外的选择使用底部Tab导航, 通过这种方式,可以很好的把页面层级分化,很好的提高用户体验.相信,很多Android开发者,都使用到过这种经典 ...

  2. [Android]--RadioGroup+RadioButton实现底部导航栏

    RadioGroup+RadioButton组合方式打造简单实用的底部导航栏 代码块: <?xml version="1.0" encoding="utf-8&qu ...

  3. Android Fragment实现微信底部导航

    1.XML布局 (1)主界面 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout x ...

  4. Android之framework修改底部导航栏NavigationBar动态显示和隐藏

     原文链接 http://blog.csdn.net/way_ping_li/article/details/45727335 git diff diff --git a/frameworks/bas ...

  5. Android (争取做到)最全的底部导航栏实现方法

    本文(争取做到)Android 最全的底部导航栏实现方法. 现在写了4个主要方法. 还有一些个人感觉不完全切题的方法也会简单介绍一下. 方法一. ViewPager + List<View> ...

  6. ViewPager+GridView实现首页导航栏布局分页效果

    如图是效果图用ViewPager+GridView实现首页导航栏布局分页效果来实现的效果 Demo下载地址:http://download.csdn.net/detail/qq_29774291/96 ...

  7. Android应用底部导航栏(选项卡)实例

    现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图: 其 ...

  8. Android学习笔记- Fragment实例 底部导航栏的实现

    1.要实现的效果图以及工程目录结构: 先看看效果图吧: 接着看看我们的工程的目录结构: 2.实现流程: Step 1:写下底部选项的一些资源文件 我们从图上可以看到,我们底部的每一项点击的时候都有不同 ...

  9. [置顶] xamarin android Fragment实现底部导航栏

    前段时间写了篇关于Fragment的文章,介绍了基础的概念,用静态和动态的方式加载Fragment  Xamarin Android Fragment的两种加载方式.下面的这个例子介绍xamarin ...

随机推荐

  1. 【AI in 美团】深度学习在OCR中的应用

    AI(人工智能)技术已经广泛应用于美团的众多业务,从美团App到大众点评App,从外卖到打车出行,从旅游到婚庆亲子,美团数百名最优秀的算法工程师正致力于将AI技术应用于搜索.推荐.广告.风控.智能调度 ...

  2. dSploitzANTI渗透教程之修改MAC地址与Wifi监听器

    dSploitzANTI渗透教程之修改MAC地址与Wifi监听器 dSploitzANTI基本配置 渗透测试是一种安全性较大的工作.所以,在实施渗透测试之前进行一些简单设置.如修改MAC地址.了解网络 ...

  3. 机器学习之路:python 集成分类器 随机森林分类RandomForestClassifier 梯度提升决策树分类GradientBoostingClassifier 预测泰坦尼克号幸存者

    python3 学习使用随机森林分类器 梯度提升决策树分类 的api,并将他们和单一决策树预测结果做出对比 附上我的git,欢迎大家来参考我其他分类器的代码: https://github.com/l ...

  4. BZOJ.2716.[Violet3]天使玩偶(K-D Tree)

    题目链接 KD-Tree.因为插入过多点后可能会退化成链,所以左/右子树sz > α*整棵子树sz时对整棵子树进行重构. 树的节点数必须是3n?why?洛谷,BZOJ都这样..(数据范围错了吧 ...

  5. bzoj 2406 二分+有源有汇上下界网络流可行流判定

    弱爆了,典型的行列建模方式,居然想不到,题做少了,总结少了...... 二分答案mid s----------------------->i行-----------------------> ...

  6. Trie树 理解

    Trie树的理解 Trie树又称单词查找树,字典树,是哈希树的变种: 优点在于:最大限度地减少无谓的字符串比较,查询效率比哈希高: 缺点在于:空间消耗很大: 性质 其基本性质可以归纳为: 跟结点不包括 ...

  7. UVA 11947 Cancer or Scorpio 水题

    Cancer or Scorpio Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://uva.onlinejudge.org/index.php? ...

  8. hdoj 4445 Crazy Tank 物理题/枚举角度1

    Crazy TankTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. 证明 O(n/1+n/2+…+n/n)=O(nlogn)

    前言 在算法中,经常需要用到一种与调和级数有关的方法求解,在分析该方法的复杂度时,我们会经常得到\(O(\frac{n}{1}+\frac{n}{2}+\ldots+\frac{n}{n})\)的复杂 ...

  10. alpha冲刺——代码规范、冲刺任务与计划(追光的人)

    代码规范 代码规范整合了自身项目实践还有诸多好的大公司的代码规范.如阿里巴巴开发手册.华为Java规范.W3C前端规范等. 由于内容过于详细和细致,为了方便查看,将其放置在了showDoc网站上(同时 ...