-
-
Save codeforfun-jp/01f287efdf8bc696b88d09a7fda5ddcd to your computer and use it in GitHub Desktop.
【Kotlin】How to create an option menu 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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