1. ActionBar
2. 테마 설정
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.AndroidEx"
parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
1. Menu
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
// 2번째 : 메뉴의 식별자(이벤트 처리시 사용), 4번째 : 메뉴의 문자열
val menuItem1: MenuItem? = menu?.add(0, 0, 0, "menu1")
val menuItem1: MenuItem? = menu?.add(0, 1, 0, "menu2")
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean = when(item.itemId){
0 -> {
true
}
1 -> {
true
}
else -> super.onOptionsItemSelected(item)
1. MenuInflater
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu1"
android:title="menu1"/>
<item
android:id="@+id/menu2"
android:title="menu2"/>
</menu>
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return super.onCreateOptionsMenu(menu)
}
2. Action Item
<item
android:id="@+id/menu2"
android:icon="@android:drawable/ic_menu_add"
android:title="menu2"
app:showAsAction="always" />
3. Action View
<item
android:id="@+id/menu3"
android:title="menu3"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="always"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>