Android底部欄,簡(jiǎn)單最實(shí)用,需要幾個(gè),由你定義。。。

開發(fā)Android已經(jīng)有些時(shí)日了,接觸了很多APP結(jié)構(gòu),大部分的APP結(jié)構(gòu)都是如此!!!


微信底部欄

這樣的APP模板已經(jīng)在當(dāng)下很成熟了,開發(fā)中,實(shí)現(xiàn)這種底部導(dǎo)航欄的方式也有很多,如:

RadioGroup+RadioButton,LinearLayout線性布局,TabLayout+ViewPager等,然而我們都需要設(shè)置一系列的監(jiān)聽,來(lái)實(shí)現(xiàn)切換fragment,開發(fā)自然會(huì)麻煩許多,今天給大家推薦一個(gè)使用的View(GYBottomBar),使用起來(lái),非常的方便,省去了很多的麻煩,附上地址(https://github.com/gyadministrator/GYBottomBar

實(shí)現(xiàn)效果如下:


怎樣使用?

Gradle引入方式:

allprojects {

repositories {

maven {

url 'https://jitpack.io'

}

}

}

dependencies {

implementation 'com.github.gyadministrator:GYBottomBar:1.3'

}

Maven引入方式:

第一步,添加到build文件中

jitpack.io

https://jitpack.io

第二步,添加依賴

com.github.gyadministrator

GYBottomBar

1.3

在activity使用,非常簡(jiǎn)單。

在xml中添加這個(gè)view。


activity中使用

package com.android.gybottombar;

import android.widget.Toast;

import com.android.bottombar.activity.GYBottomActivity;

import com.android.bottombar.model.GYBarItem;

import com.android.bottombar.view.GYBottomBarView;

import com.android.gybottombar.fragment.InfoFragment;

import com.android.gybottombar.fragment.ContactFragment;

import com.android.gybottombar.fragment.FindFragment;

import com.android.gybottombar.fragment.MyFragment;

public class MainActivity extends GYBottomActivity implements GYBottomBarView.IGYBottomBarChangeListener {

private GYBottomBarView bottomView;

@Override

public void onSelected(int position) {

Toast.makeText(this, "點(diǎn)擊了" + position, Toast.LENGTH_SHORT).show();

}

@Override

protected void initBarItems() {

barItems.add(new GYBarItem("微信", R.mipmap.home_normal));

barItems.add(new GYBarItem("通信錄", R.mipmap.category_normal));

barItems.add(new GYBarItem("發(fā)現(xiàn)", R.mipmap.service_normal));

barItems.add(new GYBarItem("我", R.mipmap.mine_normal));

}

@Override

protected void initFragment() {

fragments.add(InfoFragment.newInstance());

fragments.add(ContactFragment.newInstance());

fragments.add(FindFragment.newInstance());

fragments.add(MyFragment.newInstance());

}

@Override

protected void initSelectIcons() {

icons.add(R.mipmap.home_selected);

icons.add(R.mipmap.category_selected);

icons.add(R.mipmap.service_selected);

icons.add(R.mipmap.mine_selected);

}

@Override

protected int initContentView() {

return R.layout.activity_main;

}

@Override

protected GYBottomBarView getBottomBarView() {

return bottomView;

}

@Override

protected int initContainerId() {

return R.id.fl_container;

}

@Override

protected GYBottomBarView.IGYBottomBarChangeListener initChangeListener() {

return this;

}

@Override

protected void initView() {

bottomView = findViewById(R.id.bottomView);

}

@Override

protected void initPositionBadge() {

super.initPositionBadge();

bottomView.setPositionBadge(0, 6);

bottomView.setPositionBadge(1, 0);

bottomView.setPositionBadge(2, 100);

}

}


bottomView.setPositionBadge(3, -1);

num設(shè)置為小于0的時(shí)候,顯示小圓點(diǎn)

這樣你就可以省去很多麻煩了!!!!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容