Demo
// 메뉴 장착
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mymenu, menu);
return true;
}
// 메뉴 클릭 이벤트
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.create_new:
Toast.makeText(this, "하이헬로", Toast.LENGTH_SHORT).show();
return true;
case R.id.open:
Toast.makeText(this, "난승주라고해", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
menu/mymenu.xml
<?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/new_game"
android:icon="@drawable/ic_launcher_background"
android:title="새로운 게임"
app:showAsAction="ifRoom" />
<item
android:id="@+id/help"
android:icon="@drawable/ic_launcher_foreground"
android:title="도움말" >
<menu>
<item
android:id="@+id/create_new"
android:title="다시 만들기" />
<item
android:id="@+id/open"
android:title="열기" />
</menu>
</item>
</menu>
'System Programming > Android' 카테고리의 다른 글
[Android/Java] Sharedpreferences로 임시저장(알림같은 설정값 저장) (0) | 2021.06.12 |
---|---|
[Android/Java] Intent (0) | 2021.06.12 |
[Android/Java] Canvas, touch event 처리 (0) | 2021.06.06 |
[Android/Java] 암시적 Intent 명시적 Intent (0) | 2021.06.05 |
[01] vscode, android studio에서 환경세팅 (0) | 2021.05.25 |