Skip to content

Instantly share code, notes, and snippets.

View waseefakhtar's full-sized avatar
🎯
Focusing

Waseef Akhtar waseefakhtar

🎯
Focusing
View GitHub Profile
setSupportActionBar(findViewById(R.id.toolbar))
val drawer = findViewById(R.id.drawer)
val drawerToggle = ActionBarDrawerToggle(this, drawer, R.string.open, R.string.close)
drawer.addDrawerListener(drawerToggle)
drawerToggle.syncState()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
drawer.openDrawer(GravityCompat.START)
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START)
} else {
super.onBackPressed()
}
}
<resources>
<attr name="colorNavigationItem" format="color" />
<attr name="colorNavigationItemSelected" format="color" />
<attr name="drawableNavigationItemBackground" format="reference" />
</resources>
<item name="colorNavigationItem">@color/menu_item_color_state</item>
<item name="colorNavigationItemSelected">@color/colorWhite</item>
<item name="drawableNavigationItemBackground">@drawable/menu_background_color_state</item>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorNavigationItemSelected" android:state_checked="true" />
<item android:color="?attr/colorPrimary" android:state_checked="false"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/colorPrimary"
android:state_checked="true"
/>
</selector>
<color name="colorWhite">#FFFFFF</color>
<style name="Widget.Custom.NavigationView" parent="Widget.Design.NavigationView">
<item name="itemIconTint">?attr/colorNavigationItem</item>
<item name="itemTextColor">?attr/colorNavigationItem</item>
<item name="itemBackground">?attr/drawableNavigationItemBackground</item>
</style>