第一步在布局添加自定义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);
}