资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android底部,android底部导航栏切换

超简单,几行代码搞定Android底部导航栏

咳咳,答应过年增加新功能的,没想到拖到现在,延迟了一个来月,尴尬,尴尬

霍邱网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、响应式网站等网站项目制作,到程序开发,运营维护。创新互联建站从2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

那个,我们先忽略这尴尬的事情吧,进入正题才是最重要滴

老规矩,先上效果图:

跟原来的图有个很明显的区别,你们也一定都发现了,对不对。那么显眼的小红点,一定都看到了吧。

当然除了这个,还增加了一项功能,虽然不是很明显,但相信也有小伙伴发现了吧,截图的这俩手机屏幕明显大小不同,但是底部导航栏的大小还是相差不大滴。

是的,你们没有看多,这次不仅增加了小红点功能,还增加了底部导航栏的适配,你没有听错,以后底部导航栏也不用那些dp、sp了,都按照UI妹子们标注的px来就可以了,再也不用为了底部导航栏去跟UI妹子解释啥叫dp了。

好了,效果图展示完了,现在该进入枯燥的使用介绍了。

由于这次改动有点大,所以,先介绍下上个稳定版本的用法,到底是用最新的,还是用原来的,就看各位小伙伴的意愿了

上个稳定版本是1.1.3的,引用方式如下

compile 'com.hjm:BottomTabBar:1.1.3'

具体用法如下(备注都加好了,我也就不多废话了):

最新版本是1.2.2的,引用方式如下

compile 'com.hjm:BottomTabBar:1.2.2'

其实1.2.0与1.1.3区别并不大,只有4点改动:

现在默认的,分割线高度都是设置的1个像素。这里以后也固定都用这个默认的高度了,不再对外提供修改的方法。

这就是新增加的适配了,多的也不说了,你们都懂的

标准尺寸,就是UI妹子给你提供的效果图的屏幕尺寸,只要在init()方法里添加上标准尺寸,你就可以放肆的使用px了

这个方法就是控制小红点显示的方法了,index就是需要显示或者隐藏小红点的TabItem,isShow是一个boolean类型的参数,他是控制小红点是否显示的,如果为true,就会显示小红点;如果为false,就会隐藏小红点

1.2.2版本新增了两个方法

介绍到这里,超简单的底部导航栏,第二阶段就可以告一段落了。以后还会持续优化,完善的。

第三阶段我打算封装一下有中间凸起的底部导航栏,这个功能我本地已经做了,但是封装进去的时候,封装的不理想,这次就没有上线,留作下次了。

最后,再上个 GitHub 地址

Android实现底部tabbar按钮突出效果

在某些情况下,我们可能需要使底部tabbar的中间按钮突出,即类似于如下的效果:

在android要实现该效果,十分简单,只需要在按钮的父布局将android:clipChildren属性设置为false:

并设置按钮的layout_gravity为bottom:

示例布局文件如下:

其中android:clipChildren属性的作用为 是否限制子View不超过父布局,默认情况下是为true。当该属性为true时,子View超出父布局的部分会被裁剪。 因此,将该属性设置为false,父布局不再裁剪子View超出父布局的部分,就能实现突出按钮的效果了。

android实现底部导航有几种方

四个方面、

使用LinearLayout + TextView实现了底部导航栏的效果

首先看看工程目录:

Step 1:实现底部选项的一些资源文件

图片Drawable资源:tab_menu_deal.xml

?xml version="1.0" encoding="utf-8"?

selector xmlns:android=""

item android:drawable="@mipmap/ic_menu_deal_on" android:state_selected="true"/

item android:drawable="@mipmap/ic_menu_deal_off"/

/selector1234512345

不用做过多解释了吧,点击图片,变换图片。

其他三个依葫芦画瓢。

文字资源:tab_menu_deal_text.xml

?xml version="1.0" encoding="utf-8"?

selector xmlns:android=""

item android:color="@color/text_blue" android:state_selected="true"/

item android:color="@color/text_gray" /

/selector12345671234567

背景资源 tab_menu_bg.xml:

?xml version="1.0" encoding="utf-8"?

selector xmlns:android=""

item android:state_selected="true"

shape

solid android:color="#FFC4C4C4"/

/shape

/item

item

shape

solid android:color="@color/transparent" /

/shape

/item

/selector123456789101112131415123456789101112131415

Step 2:编写我们的Activity布局

activity_main.xml:

?xml version="1.0" encoding="utf-8"?

RelativeLayout xmlns:android=""

xmlns:tools=""

android:layout_width="match_parent"

android:layout_height="match_parent"

RelativeLayout

android:id="@+id/tab_title"

android:layout_width="match_parent"

android:layout_height="48dp"

android:background="@color/transparent"

TextView

android:id="@+id/txt_top"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:textSize="18sp"

android:textColor="@color/text_gray"

android:text= "@string/infomation" /

View

android:layout_width="match_parent"

android:layout_height="2px"

android:background="@color/text_gray"

android:layout_alignParentBottom="true"/

/RelativeLayout

LinearLayout

android:id="@+id/tab_menu"

android:layout_width="match_parent"

android:layout_height="56dp"

android:orientation="horizontal"

android:layout_alignParentBottom="true"

TextView

android:id="@+id/txt_deal"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tab_menu_bg"

android:drawablePadding="3dp"

android:drawableTop="@drawable/tab_menu_deal"

android:gravity="center"

android:textColor="@drawable/tab_menu_deal_text"

android:text="点餐"/

TextView

android:id="@+id/txt_poi"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tab_menu_bg"

android:drawablePadding="3dp"

android:drawableTop="@drawable/tab_menu_poi"

android:gravity="center"

android:textColor="@drawable/tab_menu_poi_text"

android:text="商铺"/

TextView

android:id="@+id/txt_user"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tab_menu_bg"

android:drawablePadding="3dp"

android:drawableTop="@drawable/tab_menu_user"

android:gravity="center"

android:textColor="@drawable/tab_menu_user_text"

android:text="用户"/

TextView

android:id="@+id/txt_more"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/tab_menu_bg"

android:drawablePadding="3dp"

android:drawableTop="@drawable/tab_menu_more"

android:gravity="center"

android:textColor="@drawable/tab_menu_more_text"

android:text="更多"/

/LinearLayout

View

android:id="@+id/div_tab_bar"

android:layout_width="match_parent"

android:layout_height="2px"

android:background="@color/text_gray"

android:layout_above="@id/tab_menu"/

FrameLayout

android:id="@+id/fragment_container"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_below="@id/tab_title"

android:layout_above="@id/tab_menu"

android:background="@color/transparent"

/FrameLayout

/RelativeLayout

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102


当前文章:android底部,android底部导航栏切换
URL地址:http://cdkjz.cn/article/dscecig.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220