大飞

大飞 关注TA

挑战一切!

大飞

大飞

关注TA

挑战一切!

  •  世界的顶端
  • 混口饭吃
  • 写了333,609字

最近回复

该文章投稿至Nemo社区   Android  板块 复制链接


重复造轮子,打造自己的底部导航栏

发布于 2017/06/05 13:46 2,005浏览 2回复 1,422

第一步在布局添加自定义view 
android:id="@+id/nv_tab" 

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.rongke.mifan.navigationview.MainActivity">

<com.rongke.mifan.navigationview.NavigationView
android:id="@+id/nv_tab"
android:layout_centerVertical="true"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="100px"/>
</RelativeLayout>

第二步 activity 初始化 

private void initView() {
NavigationView nv_tab= (NavigationView) findViewById(R.id.nv_tab);
Map map = new LinkedHashMap<>();
map.put("首页", R.drawable.selector_home);
map.put("找货", R.drawable.selector_find_goods);
map.put("商圈", R.drawable.selector_business_circle);
map.put("购物车", R.drawable.selector_shop_cart);
map.put("我的", R.drawable.selector_mine);
nv_tab.setNaviga(map, new NavigationView.NavigaClick() {
@Override
public void onClick(int position) {
Toast.makeText(getApplicationContext(),"选中索引:"+position,Toast.LENGTH_SHORT).show();
}
});
AutoUtils.auto(this);


//未读数显示
nv_tab.setUnRead(0,2);
}

GitHub:https://github.com/tzz2015/NavigationView

FFA38R

点赞(0)
点了个评