Java Code Examples for android.support.design.widget.NavigationView

The following examples show how to use android.support.design.widget.NavigationView. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: kute   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.landing);

    // Set a Toolbar to replace the ActionBar.
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Find our drawer view
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Find our drawer view
    nvDrawer = (NavigationView) findViewById(R.id.nvView);
    // Setup drawer view
    setupDrawerContent(nvDrawer);



}
 
Example 2
Source Project: android-atleap   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.activity_main_drawer_open, R.string.activity_main_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);
}
 
Example 3
Source Project: ClipPathLayout   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    mContainer = findViewById(R.id.fragment_container);
    RandomTransitionPathGenerator generator =
            new RandomTransitionPathGenerator(new CirclePathGenerator());
    generator.add(new OvalPathGenerator());
    generator.add(new RhombusPathGenerator());
    mTransitionAdapter = new TransitionAdapter(generator);
    mTransitionAdapter.setImmediately(true);
    mContainer.setAdapter(mTransitionAdapter);
    switchFragment(new ScrollTransitionFragment(), false);
}
 
Example 4
Source Project: mobius-android-sample   Source File: TasksActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupDrawerContent(NavigationView navigationView) {
  navigationView.setNavigationItemSelectedListener(
      menuItem -> {
        switch (menuItem.getItemId()) {
          case R.id.list_navigation_menu_item:
            // Do nothing, we're already on that screen
            break;
          case R.id.statistics_navigation_menu_item:
            Intent intent = new Intent(TasksActivity.this, StatisticsActivity.class);
            startActivity(intent);
            break;
          default:
            break;
        }
        // Close the navigation drawer when an item is selected.
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        return true;
      });
}
 
Example 5
Source Project: RetroFacebook   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 6
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if(getSupportActionBar() == null) {
        setSupportActionBar(toolbar);
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    mDrawerLayout.addDrawerListener(toggle);
    toggle.syncState();

    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    mNavigationView.setNavigationItemSelectedListener(this);

    selectNavigationItem(getNavigationDrawerID());

    View mainContent = findViewById(R.id.main_content);
    if (mainContent != null) {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    }
}
 
Example 7
Source Project: java-n-IDE-for-Android   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
public void initView(Bundle savedInstanceState) {
    mDrawerLayout.addDrawerListener(this);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            mDrawerLayout.closeDrawers();
            return mMenuEditor.onOptionsItemSelected(item);
        }
    });
    View tab = findViewById(R.id.img_tab);
    if (tab != null) {
        tab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                insertTab(v);
            }
        });
    }
    mCompileProgress = findViewById(R.id.compile_progress);
}
 
Example 8
Source Project: BreadcrumbToolbar   Source File: BreadcrumbActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void bindViews() {
    // Bind toolbar
    toolbar = (BreadcrumbToolbar) findViewById(R.id.toolbar);
    // We can't use setSupportActionBar()
    toolbar.setBreadcrumbToolbarListener(this);
    toolbar.setTitle(R.string.app_name);
    // Set animated drawer icon to toolbar
    DrawerArrowDrawable drawerArrow = new DrawerArrowDrawable(this);
    drawerArrow.setColor(ContextCompat.getColor(this, android.R.color.white));
    toolbar.setNavigationIcon(drawerArrow);
    getSupportFragmentManager().addOnBackStackChangedListener(this);

    // Bind drawer and toggle button
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    bindDrawerToggle();
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    navigationView.setCheckedItem(R.id.nav_home);

    // Bind FAB
    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(this::openBreadCrumbFragment);
}
 
Example 9
Source Project: Android_Blog_Demos   Source File: NavigationViewActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void setupDrawerContent(NavigationView navigationView)
    {
        navigationView.setNavigationItemSelectedListener(

                new NavigationView.OnNavigationItemSelectedListener()
                {

                    private MenuItem mPreMenuItem;

                    @Override
                    public boolean onNavigationItemSelected(MenuItem menuItem)
                    {
//                        if (mPreMenuItem != null) mPreMenuItem.setChecked(false);
                        menuItem.setChecked(true);
//                        mDrawerLayout.closeDrawers();
//                        mPreMenuItem = menuItem;
                        return true;
                    }
                });
    }
 
Example 10
Source Project: TimeTable   Source File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void initAll() {
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    PreferenceManager.setDefaultValues(this, R.xml.settings, false);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    setupFragments();
    setupCustomDialog();
    setupSevenDaysPref();

    if(switchSevenDays) changeFragments(true);

    setDailyAlarm();
}
 
Example 11
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example 12
Source Project: SensorsAndAi   Source File: HomeActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate ( savedInstanceState );
    setContentView ( R.layout.activity_home );
    Toolbar toolbar = (Toolbar) findViewById ( R.id.toolbar );
    setSupportActionBar ( toolbar );



    DrawerLayout drawer = (DrawerLayout) findViewById ( R.id.drawer_layout );
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close );
    drawer.addDrawerListener ( toggle );
    toggle.syncState ();

    NavigationView navigationView = (NavigationView) findViewById ( R.id.nav_view );
    navigationView.setNavigationItemSelectedListener ( this );
}
 
Example 13
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                        case R.id.list_navigation_menu_item:
                            NavUtils.navigateUpFromSameTask(StatisticsActivity.this);
                            break;
                        case R.id.statistics_navigation_menu_item:
                            // Do nothing, we're already on that screen
                            break;
                        case R.id.settings_navigation_menu_item:
                            Intent aboutIntent =
                                    new Intent(StatisticsActivity.this, SettingsActivity.class);
                            startActivity(aboutIntent);
                        default:
                            break;
                    }
                    // Close the navigation drawer when an item is selected.
                    menuItem.setChecked(true);
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
}
 
Example 14
Source Project: XKik   Source File: MainActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); // main activity
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // toolbar
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    getSupportFragmentManager().beginTransaction().replace(R.id.contentframe, new main_fragment()).commit();

    Settings.verifyStoragePermissions(this); // make sure we can access settings


    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
            .build();
    ImageLoader.getInstance().init(config);
}
 
Example 15
Source Project: stynico   Source File: gifa.java    License: MIT License 6 votes vote down vote up
public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);	
        setContentView(R.layout.apktoolmain);

	StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary));
	NavigationView navigationView = (NavigationView) findViewById(R.id.nv_main_navigation);
        navigationView.setNavigationItemSelectedListener(this);

	toolbar = (android.support.v7.widget.Toolbar)
	    findViewById(R.id.toolbar);
//		初始化Toolbar控件
	setSupportActionBar(toolbar);
//		用Toolbar取代ActionBar
	//toolbar.setTitleTextColor(getResources().getColor(R.color.text_font_white));//标题颜色
	//toolbar.setSubtitleTextColor(getResources().getColor(R.color.text_font_white));//副标题颜色

    }
 
Example 16
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_geometry_descartes);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    mPager = (ViewPager) findViewById(R.id.viewpager);
    mPager.setOffscreenPageLimit(mCount);
    PagerApdater mAdapter = new PagerApdater(getSupportFragmentManager(), this);
    mPager.setAdapter(mAdapter);
    mPager.addOnPageChangeListener(this);

    mTab = (TabLayout) findViewById(R.id.tab);
    mTab.setupWithViewPager(mPager, true);
}
 
Example 17
Source Project: OpenHub   Source File: BaseDrawerActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void initStartDrawerView() {
    if (navViewStart == null) return;
    if (startDrawerEnable) {
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout,
                toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        toggle.syncState();
        navViewStart.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                return BaseDrawerActivity.this.onNavigationItemSelected(item, true);
            }
        });
    } else {
        drawerLayout.removeView(navViewStart);
    }
}
 
Example 18
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_debug);
  ButterKnife.bind(this);

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
          .setAction("Action", null).show();
    }
  });

  initNavigationDrawer();

  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);

  // Local web server
  setupWebServer();
}
 
Example 19
Source Project: MousePaint   Source File: HomeActivity.java    License: MIT License 6 votes vote down vote up
private void init() {
    view_hide.setOnClickListener(this);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationIcon(R.drawable.ic_menu);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    if (mNavigationView != null) {
        setupDrawerContent(mNavigationView);
        mNavigationView.setCheckedItem(R.id.nav_home);
    }

    mHomeFragment = HomeFragment.newInstance();
    switchFragment(TAG_HOME, mHomeFragment);

    setupRecyclerView();

    mIntent = new Intent();

    handFabPathAndSearch();
}
 
Example 20
Source Project: Hillffair17   Source File: HomescreenNew.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    initCollapsingToolbar();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, 0, 0);
    actionBarDrawerToggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    pref = new SharedPref(this);

    if(new Connection(this).isInternet()){
        profileBasicInfo(pref.getUserId());
    }

}
 
Example 21
Source Project: atlas   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
        Log.e("aa","bbb");


        ((BottomNavigationView)findViewById(R.id.navigation)).setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
//        mActivityDelegate = new ActivityGroupDelegate(this,savedInstanceState);
        switchToActivity("com.taobao.firstbundle.FirstBundleActivity");
    }
 
Example 22
Source Project: androidtestdebug   Source File: NotesActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notes);


    // Set up the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    // Set up the navigation drawer.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    if (null == savedInstanceState) {
        initFragment(NotesFragment.newInstance());
    }
}
 
Example 23
Source Project: YalpStore   Source File: BaseActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    NavigationView navigationView = findViewById(R.id.nav_view);
    if (null == navigationView) {
        return;
    }
    TextView userNameView = navigationView.getHeaderView(0).findViewById(R.id.username);
    TextView deviceView = navigationView.getHeaderView(0).findViewById(R.id.device);
    if (null == userNameView || null == deviceView) {
        return;
    }
    String currentUserName = null == YalpStoreApplication.user.getUserName()
        ? ""
        : YalpStoreApplication.user.getUserName()
    ;
    String currentDeviceName = null == YalpStoreApplication.user.getDeviceDefinitionDisplayName()
        ? ""
        : YalpStoreApplication.user.getDeviceDefinitionDisplayName()
    ;
    if (!currentUserName.equals(userNameView.getText().toString())
        || !currentDeviceName.equals(deviceView.getText().toString())
    ) {
        redrawAccounts();
    }
}
 
Example 24
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_base);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    frameLayout = (FrameLayout) findViewById(R.id.nav_content_frame);
    navImage = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.nav_header_image);
}
 
Example 25
Source Project: design-support-demo   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  // load saved navigation state if present
  if (null == savedInstanceState) {
    mNavItemId = R.id.drawer_item_1;
  } else {
    mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID);
  }

  // listen for navigation events
  NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
  navigationView.setNavigationItemSelectedListener(this);

  // select the correct nav menu item
  navigationView.getMenu().findItem(mNavItemId).setChecked(true);

  // set up the hamburger icon to open and close the drawer
  mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.open,
      R.string.close);
  mDrawerLayout.setDrawerListener(mDrawerToggle);
  mDrawerToggle.syncState();

  navigate(mNavItemId);
}
 
Example 26
Source Project: Saiy-PS   Source File: ActivityHome.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Self explanatory utility
 */
private void setupNavigation() {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "setupNavigation");
    }

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
}
 
Example 27
Source Project: streamsupport   Source File: MainActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
 
Example 28
Source Project: android-auto-call-recorder   Source File: MainOldActivity.java    License: MIT License 5 votes vote down vote up
private void setupDrawerContent(final NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    //Checking if the item is in checked state or not, if not make it in checked state
                    selectDrawerItem(menuItem);
                    return true;
                }
            });
}
 
Example 29
protected void registerDrawer() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if(iDrawerClosedCallBack != null){
                iDrawerClosedCallBack.onDrawerClosed();
            }
        }
    };
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    tintNavView(ThemeController.getCurrentColor().mainColor);
    headerLayout = (FrameLayout) LayoutInflater.from(this).inflate(R.layout.nav_header_main, null);
    ImageView imageView=(ImageView)headerLayout.findViewById(R.id.nav_header_back);
    imageView.setImageDrawable(ImageProcessor.zoomImageMin(
            ContextCompat.getDrawable(this, R.drawable.navigation_header)
            , getResources().getDisplayMetrics().widthPixels
            , getResources().getDisplayMetrics().widthPixels));
    navigationView.addHeaderView(headerLayout);
}
 
Example 30
Source Project: AndroidStarterKit   Source File: SampleActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  if (savedInstanceState == null) {
    getSupportFragmentManager()
        .beginTransaction()
        .add(R.id.container, new SampleFragment())
        .commit();
  }

  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);

  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      Snackbar.make(view, "Welcome to AndroidStarterKit!", Snackbar.LENGTH_LONG)
          .setAction("Action", null).show();
    }
  });

  DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  drawer.setDrawerListener(toggle);
  toggle.syncState();

  NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  navigationView.setNavigationItemSelectedListener(this);
}