1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.android.test.uibench; 17 18import android.os.Bundle; 19import android.support.design.widget.NavigationView; 20import android.support.v4.view.GravityCompat; 21import android.support.v4.widget.DrawerLayout; 22import android.support.v7.app.ActionBarDrawerToggle; 23import android.support.v7.app.AppCompatActivity; 24import android.support.v7.widget.Toolbar; 25import android.view.MenuItem; 26 27public class NavigationDrawerActivity extends AppCompatActivity 28 implements NavigationView.OnNavigationItemSelectedListener { 29 30 @Override 31 protected void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 setContentView(R.layout.activity_navigation_drawer); 34 Toolbar toolbar = findViewById(R.id.toolbar); 35 setSupportActionBar(toolbar); 36 DrawerLayout drawer = findViewById(R.id.drawer_layout); 37 ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 38 this, drawer, toolbar, R.string.navigation_drawer_open, 39 R.string.navigation_drawer_close); 40 drawer.setDrawerListener(toggle); 41 toggle.syncState(); 42 43 NavigationView navigationView = findViewById(R.id.nav_view); 44 navigationView.setNavigationItemSelectedListener(this); 45 } 46 47 @Override 48 public boolean onNavigationItemSelected(MenuItem item) { 49 DrawerLayout drawer = findViewById(R.id.drawer_layout); 50 drawer.closeDrawer(GravityCompat.START); 51 return true; 52 } 53} 54