Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created August 18, 2022 07:36
Show Gist options
  • Save codeforfun-jp/01f287efdf8bc696b88d09a7fda5ddcd to your computer and use it in GitHub Desktop.
Save codeforfun-jp/01f287efdf8bc696b88d09a7fda5ddcd to your computer and use it in GitHub Desktop.
【Kotlin】How to create an option menu 2
package com.example.optionmenusample
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.option_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// when (item.itemId) {
// R.id.action_home ->
// R.id.action_user ->
// R.id.action_map ->
// }
Toast.makeText(this, "「${item.title}」が押されました。", Toast.LENGTH_SHORT).show()
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment