Android Navigation Bar

At present, the head navigation of many apps is similar to non-navigation. In order to simplify development and reduce coupling, the encapsulated NavigationBar has been used.

github address

NavigationBar currently supports features

1. Add menu from the left, support multiple. (menu can be string, drawable, layout) 2, add menu from the right, support multiple. (menu can be string, drawable, layout) 3. Set the text title in the middle. 4. Set the title to drawable left, top, right, bottom. 5. Replace the title view with a custom View. 6. Add/remove top layer view. 7. Unified strong menu click event.

code use case

        NavigationBar navBar1 = (NavigationBar) findViewById(R.id.nav_bar_1);
        navBar1.setTitle("Nav1");//中间标题
        navBar1.addFromLeft(NavItems.search_img);//左侧添加可多个
        navBar1.addFromRight(NavItems.search_txt);//右侧添加可多个
        navBar1.setNavgationListener(navgationListener);
        //
        NavigationBar navBar2 = (NavigationBar) findViewById(R.id.nav_bar_2);
        navBar2.setTitle("Nav2");
        navBar2.addFromLeft(NavItems.search_img);//左侧1
        navBar2.addFromLeft(NavItems.save);//左侧2
        navBar2.addFromRight(NavItems.messgae_count_view);//右侧自定义View
        navBar2.setNavgationListener(navgationListener);
        //
        NavigationBar navBar3 = (NavigationBar) findViewById(R.id.nav_bar_3);
        navBar3.setTitle("View Title");
        SearchBar mSearchBar = createSearchBar();//自定义View
        navBar3.replaceTitleView(mSearchBar);//替换到标题位置
        //navBar3.addFromLeft(NavItems.save);//同时支持左右添加
        navBar3.setNavgationListener(navgationListener);

        //-----其他常用函数-----
        //添加整个导航层View
        //navBar3.addTopLayer(mSearchBar);

        //设置title的drawable
        //navBar3.setTitleTextViewDrawable(left,top,right,bottom);

        //使用Layout Id直接替换title
        //navBar3.replaceTitleView(R.layout.xxx);

        //通过res设置title
        //navBar3.setTitle(R.string.app_name);

        //设置item是否可见
        //navBar3.changeNavChildVisiable(itemId,visiable);

menu item monitor

private NavgationListener navgationListener = new NavgationListener() {
        @Override
        public void onNavigationClick(View v, NavItem item, NavigationBar nav) {
            if (item.getId() == NavItems.search_img.getId()) {
                toast("img(Search)");
            } else if (item.getId() == NavItems.search_txt.getId()) {
                toast("txt(Search)");
            } else if (item.getId() == NavItems.messgae_count_view.getId()) {
                toast("view(MsgCount)");
            } else if (item.getId() == NavItems.save.getId()) {
                toast("txt(Save)");
            }
        }
    };

menu item definition

public class NavItems {
    public static final NavItem search_img = BaseNavItem.img(R.drawable.nav_icon_search);
    public static final NavItem search_txt = BaseNavItem.text("Search");
    public static final NavItem save = BaseNavItem.text("Save");
    public static final NavItem messgae_count_view = BaseNavItem.view(R.layout.nav_item_msg_count);
}

Usually, after introducing NavigationBar, you only need to define the Item that the project needs to use.

Effect map (three simple combinations)

Effect screenshot

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324066724&siteId=291194637