大佬教程收集整理的这篇文章主要介绍了如何以编程方式触发/点击Android中的MenuItem?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<menu xmlns:android="http://scheR_421_11845@as.android.com/apk/res/android" xmlns:app="http://scheR_421_11845@as.android.com/apk/res-auto" xmlns:tools="http://scheR_421_11845@as.android.com/tools" tools:context=".MainActivity"> <item android:id="@+id/action_restart" android@R_489_6964@="Restart" android:orderInCategory="1" /> <item android:id="@+id/action_clear" android@R_489_6964@="Clear" android:orderInCategory="2" /> <item android:id="@+id/action_update" android@R_489_6964@="update" android:orderInCategory="3" /> <item android:id="@+id/action_about" android@R_489_6964@="About" android:orderInCategory="4" /> <item android:id="@+id/action_try_restart" android@R_489_6964@="Try Restart" android:orderInCategory="5" /> </menu>
我在我的onOptionsItemSELEcted方法中有这个:
@Override public Boolean onOptionsItemSELEcted(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button,so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_restart) { Toast.makeText(MainActivity.this,"Restart...",Toast.LENGTH_LONG).show(); } if (id == R.id.action_clear) { Toast.makeText(MainActivity.this,"Clear...",Toast.LENGTH_LONG).show(); } if (id == R.id.action_updatE) { Toast.makeText(MainActivity.this,"update...",Toast.LENGTH_LONG).show(); } if (id == R.id.action_about) { Toast.makeText(MainActivity.this,"About...",Toast.LENGTH_LONG).show(); } if(id == R.id.action_try_restart) { // how to click / trigger the "action_restart" from here? } return super.onOptionsItemSELEcted(item); }
我试过:
@H_7_2@menuItem actionRestart = (MenuItem) findViewById(R.id.action_restart); actionRestart; //但是actionRestart引用不提供任何类似的点击,触发器等.
我也想注意到,我是Android开发的新手,我来自PHP / JavaScript背景,所以这个级别的Java OOP对我而言都是新的.
以上是大佬教程为你收集整理的如何以编程方式触发/点击Android中的MenuItem?全部内容,希望文章能够帮你解决如何以编程方式触发/点击Android中的MenuItem?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。