Git Product home page Git Product logo

customnavview's Introduction

CustomNavView

Custom implementation of NavigationView for using custom layout for navigation items and header.

Output sample

Add CustomNavigationView in DrawerLayout

<android.support.v4.widget.DrawerLayout 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="test.jinesh.customnavigation.NavigationActivity">
    <FrameLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:id="@+id/mainContent"
        android:layout_height="match_parent">

    </FrameLayout>

    <test.jinesh.customnavigation.CustomNavigationView
        android:id="@+id/navView"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>

Set header view and items adapter

 menuAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuList);
 navView.setAdapter(menuAdapter);
 //header view and bottom margin for the header view
 navView.setHeaderView(getHeader(),20);

Set NavigationItemSelectedListner to notified about click events on nav items

navView.setOnNavigationItemSelectedListner(this);

@Override
public void onItemSelected(View view, int position) {
    switch (position) {
        case 0:
                FirstFragment firstFragment=new FirstFragment();
                ft = getSupportFragmentManager().beginTransaction();
                ft.replace(R.id.mainContent, firstFragment).commit();
                break;
         case 1:
                SecondFragment secondFragment=new SecondFragment();
                ft = getSupportFragmentManager().beginTransaction();
                ft.replace(R.id.mainContent, secondFragment).commit();
                break;
         case 2:
                ThirdFragment thirdFragment=new ThirdFragment();
                ft = getSupportFragmentManager().beginTransaction();
                ft.replace(R.id.mainContent, thirdFragment).commit();
                break;
            case 3:
                FourthFragment fourthFragment=new FourthFragment();
                ft = getSupportFragmentManager().beginTransaction();
                ft.replace(R.id.mainContent, fourthFragment).commit();
                break;
        }
        drawerLayout.closeDrawers();
    }

customnavview's People

Contributors

jineshfrancs avatar

Watchers

Naseem Akhtar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.