Issue
I need help. When I want to open the DrawableLayout, I press the toggle button there for the first time it doesn't respond. After I opened the DrawableLayout by swipe and close it, then toggle starts working properly. Here is a Youtube link to the problem and some code segment.
Segment of kotlin class
//region Drawable layout
private fun initDrawableLayout() {
setUpNavigationView()
setToolbar()
setToggleActionBar()
}
private fun setUpNavigationView() {
binding.mainNavView.bringToFront()
binding.mainNavView.setNavigationItemSelectedListener(this)
}
private fun setToggleActionBar() {
var toggle = ActionBarDrawerToggle(
this,
binding.mainDrawerLayout,
binding.mainToolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
binding.mainDrawerLayout.addDrawerListener(toggle)
toggle.syncState()
}
private fun setToolbar() {
binding.toolbarTitleTv.text = getString(R.string.home)
}
Segment of xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/main_color"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbar_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Home" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/top_navigation_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round_corners"
app:itemIconTint="@color/navigation_icons_color"
app:itemTextColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/main_toolbar"
app:menu="@menu/navigation_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/main_nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:visibility="gone"
app:headerLayout="@layout/header"
app:menu="@menu/drawable_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
Solution
In my case I needed delete visibility = gone from NavigationView in xml file. Maybe it will help to somebody.
<com.google.android.material.navigation.NavigationView
android:id="@+id/main_nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:visibility="gone"
app:headerLayout="@layout/header"
app:menu="@menu/drawable_menu" />
Answered By - Pavel Maltsev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.