android开发

OptionsMenu分组或跳转界面

2020-04-03  本文已影响0人  android_Pie

OptionsMenu分组或跳转界面

item的分组(group),分组的目的对为了让多个item同时显示或隐藏,有效或无效等
在布局中使用group进行分组
<group android:id="@+id/g01"/>

public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        //隐藏分组
        menu.setGroupVisible(R.id.g01,false);
        //添加一个Item,此item基于intent选项
        //Adding Menu Items Based on an Intent
        Intent intent =new Intent(this,OtherActivity.class);
        //在菜单中添加item
        menu.addIntentOptions(
        0,//分组id
        100,//item id
        0,//order
        this.getComponentName(),//组件名
        null,
        intent, 
        0, 
        null);
        return true;
    }
上一篇下一篇

猜你喜欢

热点阅读