我正在尝试使辅助菜单仅在按片段内的按钮时出现 类似于WhatsApp
class A_A() : Fragment(),View.OnClickListener {
var mActionMode:ActionMode.Callback?=null
override fun onClick(v: View?) {
when (v?.id) {
R.id.btn_mnu -> {
AppAppCompatActivity().startSupportActionMode(open())
}}}
inner class open: androidx.appcompat.view.ActionMode.Callback{
override fun onCreateActionMode(mode: androidx.appcompat.view.ActionMode?, menu: Menu?): Boolean {
mode!!.menuInflater.inflate(R.menu.sec_whats_menu,menu)
return true}
override fun onPrepareActionMode(mode: androidx.appcompat.view.ActionMode?, menu: Menu?): Boolean {
mode?.title="secondary"
return true}
override fun onDestroyActionMode(mode: androidx.appcompat.view.ActionMode?) {
mode?.finish()}
override fun onActionItemClicked(mode: androidx.appcompat.view.ActionMode?, item: MenuItem?): Boolean {
return true}}
}
我在上面尝试了此代码,但是在代码运行时没有显示错误 它在
崩溃 AppAppCompatActivity().startSupportActionMode(open())