| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.test.uibench; |
| 17 |
|
| 18 |
import android.os.Bundle; |
| 19 |
import android.view.MenuItem; |
| 20 |
|
| 21 |
import androidx.appcompat.app.ActionBarDrawerToggle; |
| 22 |
import androidx.appcompat.app.AppCompatActivity; |
| 23 |
import androidx.appcompat.widget.Toolbar; |
| 24 |
import androidx.core.view.GravityCompat; |
| 25 |
import androidx.drawerlayout.widget.DrawerLayout; |
| 26 |
|
| 27 |
import com.google.android.material.navigation.NavigationView; |
| 28 |
|
| 29 |
public class NavigationDrawerActivity extends AppCompatActivity |
| 30 |
implements NavigationView.OnNavigationItemSelectedListener { |
| 31 |
|
| 32 |
@Override |
| 33 |
protected void onCreate(Bundle savedInstanceState) { |
| 34 |
super.onCreate(savedInstanceState); |
| 35 |
setContentView(R.layout.activity_navigation_drawer); |
| 36 |
Toolbar toolbar = findViewById(R.id.toolbar); |
| 37 |
setSupportActionBar(toolbar); |
| 38 |
DrawerLayout drawer = findViewById(R.id.drawer_layout); |
| 39 |
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( |
| 40 |
this, drawer, toolbar, R.string.navigation_drawer_open, |
| 41 |
R.string.navigation_drawer_close); |
| 42 |
drawer.setDrawerListener(toggle); |
| 43 |
toggle.syncState(); |
| 44 |
|
| 45 |
NavigationView navigationView = findViewById(R.id.nav_view); |
| 46 |
navigationView.setNavigationItemSelectedListener(this); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public boolean onNavigationItemSelected(MenuItem item) { |
| 51 |
DrawerLayout drawer = findViewById(R.id.drawer_layout); |
| 52 |
drawer.closeDrawer(GravityCompat.START); |
| 53 |
return true; |
| 54 |
} |
| 55 |
} |