drawerLayout 안에 메인으로 보여줄 레이아웃과 서랍으로 쓸 레이아웃 (최소 두개)를 달아준다.
android:layout_gravity를 설정해주는 레이아웃이 서랍으로 쓸 레이아웃이 된다.
<?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>"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<androidx.appcompat.widget.LinearLayoutCompat 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:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/custom_toolbar"></include>
<com.prolificinteractive.materialcalendarview.MaterialCalendarView xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:app="<http://schemas.android.com/apk/res-auto>"
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
app:mcv_selectionColor="#CDDC39"
app:mcv_showOtherDates="all" />
</androidx.appcompat.widget.LinearLayoutCompat>
//네비게이션뷰만 딸랑 달지말고, 꼭 부모레이아웃 밑에 네비게이션뷰를 달아주자!!!!
//android:layout_gravity="start"<<이 달린 레이아웃이 서랍으로 쓰인다!!
(android:layout_gravity="start"<<이 달린 네비게이션뷰가 서랍으로 쓰이는게 아니다!!)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="horizontal">
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/main_nav_header"
app:menu="@menu/main_navigation_menu" />
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="<http://schemas.android.com/apk/res/android>">
<item
android:id="@+id/logout"
android:icon="@drawable/ic_baseline_menu_24"
android:title="로그아웃"
/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:padding="20dp"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/nav_profile_img"/>
<TextView
android:layout_gravity="center"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:id="@+id/nav_nickname"/>
</LinearLayout>
/**
* 네비게이션뷰
*/
//왼쪽 버튼 눌렀을 때
toolbar.setNavigationOnClickListener {
//drawer layout
binding.drawerLayout.openDrawer(GravityCompat.START)
//네비게이션뷰 헤더 안에 있는 뷰에 접근하고 싶으면 findeViewById로 불러와야한다.
val nav_nickname = findViewById<TextView>(R.id.nav_nickname)
nav_nickname.text = intent.getStringExtra("profile_nickname").toString()
val nav_profile_img = findViewById<ImageView>(R.id.nav_profile_img)
Glide.with(this)
.load(profile_image)
.circleCrop()
.into(nav_profile_img) }
//네비게이션 메뉴 선택시
//NavigationView.OnNavigationItemSelectedListener <<이것을 AppCompatActivity() 요기 옆에 같이 상속받는다
binding.navigationView.setNavigationItemSelectedListener(this)
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when(item.itemId){
R.id.logout-> UserApiClient.instance.logout {
val intent = Intent(this@MainActivity, KakaoLogin::class.java)
startActivity(intent)
}
}
return true
}