美文网首页android开发
OptionsMenu分组或跳转界面

OptionsMenu分组或跳转界面

作者: android_Pie | 来源:发表于2020-04-03 21:58 被阅读0次

    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;
        }
    

    相关文章

      网友评论

        本文标题:OptionsMenu分组或跳转界面

        本文链接:https://www.haomeiwen.com/subject/kzslphtx.html