日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

android加号底部导航栏,EasyNavigation Android 底部导航栏████几行代码实现 Tab 导航(随意定制加号,带红点消息提示) @codeKK Android开源站...

發(fā)布時(shí)間:2023/12/20 Android 60 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android加号底部导航栏,EasyNavigation Android 底部导航栏████几行代码实现 Tab 导航(随意定制加号,带红点消息提示) @codeKK Android开源站... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

幾行代碼輕松實(shí)現(xiàn)底部導(dǎo)航欄(Tab 文字圖片高度隨意更改);

中間可添加加號按鈕,也可添加文字;(足夠的屬性滿足你需要實(shí)現(xiàn)的加號樣式)

如果還不能滿足、中間可添加自定義 View;

Tab 中隨意添加小紅點(diǎn)提示、數(shù)字消息提示;

點(diǎn)擊按鈕可跳轉(zhuǎn)界面、也可作為 Tab 切換 Fragment;

2.0.+遷移 AndroidX、支持 ViewPager2;

剝離導(dǎo)航欄、不傳 Fragment 則不會(huì)創(chuàng)建 ViewPager、可自行實(shí)現(xiàn) ViewPager 使用 setupWithViewPager 方法與之關(guān)聯(lián);

支持僅圖片、僅文字的方式.;

支持字體單位修改、SP 和 DP 切換;

支持紅點(diǎn)消息大于 99、則顯示橢圓可自定義背景顏色及角度;

更多使用參考簡書;

效果圖

實(shí)現(xiàn)

依賴

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

...

maven { url 'https://jitpack.io' }

}

}

Step 2. Add the dependency

implementation 'com.github.Vincent7Wong:EasyNavigation:1.5.0'

//2.0.5 AndroidX 版本、支持 ViewPager2

implementation 'com.github.Vincent7Wong:EasyNavigation:2.0.5'

navigationBar.defaultSetting() //恢復(fù)默認(rèn)配置、可用于重繪導(dǎo)航欄

.titleItems(tabText) // Tab 文字集合 只傳文字則只顯示文字

.normalIconItems(normalIcon) // Tab 未選中圖標(biāo)集合

.selectIconItems(selectIcon) // Tab 選中圖標(biāo)集合

.fragmentList(fragments) // fragment 集合

.fragmentManager(getSupportFragmentManager())

.iconSize(20) //Tab 圖標(biāo)大小

.tabTextSize(10) //Tab 文字大小

.tabTextTop(2) //Tab 文字距 Tab 圖標(biāo)的距離

.normalTextColor(Color.parseColor("#666666")) //Tab 未選中時(shí)字體顏色

.selectTextColor(Color.parseColor("#333333")) //Tab 選中時(shí)字體顏色

.scaleType(ImageView.ScaleType.CENTER_INSIDE) //同 ImageView 的 ScaleType

.navigationBackground(Color.parseColor("#80000000")) //導(dǎo)航欄背景色

.setOnTabClickListener(new EasyNavigationBar.OnTabClickListener() {

@Override

public boolean onTabSelectEvent(View view, int position) {

//Tab 點(diǎn)擊事件 return true 頁面不會(huì)切換

return false;

}

@Override

public boolean onTabReSelectEvent(View view, int position) {

//Tab 重復(fù)點(diǎn)擊事件

return false;

}

})

.smoothScroll(false) //點(diǎn)擊 Tab Viewpager 切換是否有動(dòng)畫

.canScroll(true) //Viewpager 能否左右滑動(dòng)

.mode(EasyNavigationBar.NavigationMode.MODE_ADD) //默認(rèn) MODE_NORMAL 普通模式 //MODE_ADD 帶加號模式

.centerTextStr("發(fā)現(xiàn)")

.centerImageRes(R.mipmap.add_image)

.centerIconSize(36) //中間加號圖片的大小

.centerLayoutHeight(100) //包含加號的布局高度 背景透明 所以加號看起來突出一塊

.navigationHeight(60) //導(dǎo)航欄高度

.lineHeight(10) //分割線高度 默認(rèn) 1px

.lineColor(Color.parseColor("#ff0000"))

.centerLayoutRule(EasyNavigationBar.RULE_BOTTOM) //RULE_CENTER 加號居中 addLayoutHeight 調(diào)節(jié)位置 EasyNavigationBar.RULE_BOTTOM 加號在導(dǎo)航欄靠下

.centerLayoutBottomMargin(10) //加號到底部的距離

.hasPadding(true) //true ViewPager 布局在導(dǎo)航欄之上 false 有重疊

.hintPointLeft(-3) //調(diào)節(jié)提示紅點(diǎn)的位置 hintPointLeft hintPointTop(看文檔說明)

.hintPointTop(-3)

.hintPointSize(6) //提示紅點(diǎn)的大小

.msgPointLeft(-10) //調(diào)節(jié)數(shù)字消息的位置 msgPointLeft msgPointTop(看文檔說明)

.msgPointTop(-10)

.msgPointTextSize(9) //數(shù)字消息中字體大小

.msgPointSize(18) //數(shù)字消息紅色背景的大小

.centerAlignBottom(true) //加號是否同 Tab 文字底部對齊 RULE_BOTTOM 時(shí)有效;

.centerTextTopMargin(50) //加號文字距離加號圖片的距離

.centerTextSize(15) //加號文字大小

.centerNormalTextColor(Color.parseColor("#ff0000")) //加號文字未選中時(shí)字體顏色

.centerSelectTextColor(Color.parseColor("#00ff00")) //加號文字選中時(shí)字體顏色

.setMsgPointColor(Color.BLUE) //數(shù)字消息、紅點(diǎn)背景顏色

.setMsgPointMoreRadius(5) //消息 99+角度半徑

.setMsgPointMoreWidth(50) //消息 99+寬度

.setMsgPointMoreHeight(40) //消息 99+高度

.textSizeType(EasyNavigationBar.TextSizeType.TYPE_DP) //字體單位 建議使用 DP 可切換 SP

.setOnTabLoadListener(new EasyNavigationBar.OnTabLoadListener() { //Tab 加載完畢回調(diào)

@Override

public void onTabLoadCompleteEvent() {

navigationBar.setMsgPointCount(0, 7);

navigationBar.setMsgPointCount(1, 109);

navigationBar.setHintPoint(4, true);

}

})

//.setupWithViewPager() ViewPager 或 ViewPager2

.build();

更新

此版本較上一版本有很大更新、實(shí)現(xiàn)方式也調(diào)整了下、如有錯(cuò)誤及時(shí)反饋

2.0.+遷移 AndroidX、支持 ViewPager2;

剝離導(dǎo)航欄、不傳 Fragment 則不會(huì)創(chuàng)建 ViewPager、可自行實(shí)現(xiàn) ViewPager 使用 setupWithViewPager 方法與之關(guān)聯(lián);

新增僅圖片、僅文字的方式。titleItems 和 normalIconItems 不能同時(shí)為空。如果沒有 titleItems、則僅顯示圖片,沒有 normalIconItems 則僅顯示文字,沒有 selectIconItems 則 Tab 沒有切換效果;

新增字體單位修改、SP 和 DP 切換;

新增紅點(diǎn)消息大于 99、則顯示橢圓可自定義背景顏色及角度;

修復(fù)控件寬度計(jì)算問題;

新增重復(fù)選擇回調(diào);

方法名字諸多修改;(中間 Tab 的相關(guān)屬性由 add 改為 center/萬分抱歉)

取消 Tab 點(diǎn)擊動(dòng)畫

Demo

總結(jié)

以上是生活随笔為你收集整理的android加号底部导航栏,EasyNavigation Android 底部导航栏████几行代码实现 Tab 导航(随意定制加号,带红点消息提示) @codeKK Android开源站...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。