Hi I'm having trouble on making layout like this design because the navigation bar is difficult to make it become functional.
I have created the class like this:
class MainActivity : AppCompatActivity() {
lateinit var navigationView: NavigationView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navigationView = findViewById(R.id.navigation)
navigationView.setNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
}
private val mOnNavigationItemSelectedListener =
BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_user -> {
val fragment = UserFragment()
addFragment(fragment)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_scaner -> {
val fragment = ScannerFragment()
addFragment(fragment)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_laporan -> {
val fragment = LaporanFragment()
addFragment(fragment)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_notif ->{
val fragment = NotificationFragment()
addFragment(fragment)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_chat -> {
val fragment = LaporanFragment()
addFragment(fragment)
return@OnNavigationItemSelectedListener true
}
R.id.navigation_profile -> {
val fragment = LaporanFragment()
addFragment(fragment)
return@OnNavigationItemSelectedListener true
}
}
false
}
private fun addFragment(fragment: Fragment) = supportFragmentManager
.beginTransaction()
.setCustomAnimations(R.anim.design_bottom_sheet_slide_in, R.anim.design_bottom_sheet_slide_out)
.replace(R.id.content, fragment, fragment.javaClass.simpleName)
.commit()
}
and this is my layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"
android:paddingBottom="20dp"
android:background="#FAFAFC"
android:paddingRight="20dp"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearnama"
android:layout_marginStart="20dp"
android:padding="25dp"
android:layout_marginTop="21dp"
android:background="@drawable/bg_white_rounded"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.cardview.widget.CardView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:id="@+id/foto_profil_operator"
android:elevation="10dp"
app:cardCornerRadius="18dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="51dp"
android:layout_height="51dp"
android:scaleType="centerCrop"
android:src="@drawable/lisa" />
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/poppins"
android:layout_marginStart="15dp"
android:layout_weight="0.2"
android:gravity="left"
android:layout_gravity="center"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:text="Nama Operator" />
<ImageView
android:layout_width="200dp"
android:layout_height="match_parent"
android:foregroundGravity="right"
android:layout_gravity="end"
android:layout_weight="0"
android:src="@drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearnama"
app:layout_constraintVertical_bias="0.497">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_weight="0.1"
android:background="@drawable/bg_white_rounded"
android:padding="20dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MENU"
android:fontFamily="@font/poppins"
android:textColor="@color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="@color/white"
app:itemIconTint="@color/black"
app:itemTextColor="@color/black"
app:layout_constraintBottom_toTopOf="@+id/pp2k"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:menu="@menu/navigation">
</com.google.android.material.navigation.NavigationView>
<TextView
android:id="@+id/pp2k"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="navigation"
android:textColor="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_weight="0.5"
android:layout_marginTop="20dp"
android:background="@drawable/bg_white_rounded"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
</FrameLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I have tried several navigation listener such as navigationView.setNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
But it won't work. Maybe someone know how I can solve my problem? Thanks in advance