Skip to content

Instantly share code, notes, and snippets.

@siddhantkushwaha
Created March 26, 2021 12:06
Show Gist options
  • Save siddhantkushwaha/d81520934b529d3635e11f246f8f3946 to your computer and use it in GitHub Desktop.
Save siddhantkushwaha/d81520934b529d3635e11f246f8f3946 to your computer and use it in GitHub Desktop.
BottomAppBar
package com.siddhantkushwaha.falcon.activity
import android.os.Bundle
import com.google.android.gms.common.api.Scope
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.api.services.gmail.GmailScopes
import com.siddhantkushwaha.falcon.R
import kotlinx.android.synthetic.main.activity_home.*
class ActivityHome : ActivityBase() {
private val scope = Scope(GmailScopes.MAIL_GOOGLE_COM)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
val bottomSheetBehavior = BottomSheetBehavior.from(navigationView)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
bottomAppBar.setNavigationOnClickListener {
bottomSheetBehavior.state = when (bottomSheetBehavior.state) {
BottomSheetBehavior.STATE_EXPANDED -> BottomSheetBehavior.STATE_HIDDEN
else -> BottomSheetBehavior.STATE_EXPANDED
}
}
scrim.setOnClickListener {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
}
bottomAppBar.setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) {
R.id.search -> {
true
}
R.id.more -> {
true
}
else -> false
}
}
}
}
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#292929">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="?attr/actionBarSize">
<!-- Screen content -->
<FrameLayout
android:id="@+id/scrim"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#202020"
app:behavior_hideable="true"
app:layout_behavior="@string/bottom_sheet_behavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="200dp">
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.navigation.NavigationView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
style="@style/MyBottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorPrimaryDark"
app:menu="@menu/bottom_app_bar"
app:navigationIcon="@drawable/icon_nav_drawer" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#007ddc"
android:src="@drawable/logo_falcon_white"
app:borderWidth="0dp"
app:layout_anchor="@id/bottomAppBar"
app:tint="@android:color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment