Android底部栏,简单最实用,需要几个,由你定义。。。

开发Android已经有些时日了,接触了很多APP结构,大部分的APP结构都是如此!!!


微信底部栏

这样的APP模板已经在当下很成熟了,开发中,实现这种底部导航栏的方式也有很多,如:

RadioGroup+RadioButton,LinearLayout线性布局,TabLayout+ViewPager等,然而我们都需要设置一系列的监听,来实现切换fragment,开发自然会麻烦许多,今天给大家推荐一个使用的View(GYBottomBar),使用起来,非常的方便,省去了很多的麻烦,附上地址(https://github.com/gyadministrator/GYBottomBar

实现效果如下:


怎样使用?

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使用,非常简单。

在xml中添加这个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, "点击了" + 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("发现", 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设置为小于0的时候,显示小圆点

这样你就可以省去很多麻烦了!!!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容