Android——PopMenu

介绍

  PopMenu弹出式菜单,是古老的Android组件之一

 

属性

  在res中建立=》menu,在menu 中建立,R.menu.xml

  <menu>

    <item android:id = "@+id/ "/  android:title=" 帮助 ">

  </menu>

 

方法

  PopMenu( Context context , View bindView )

    参数:

      Context context:上下文

      View bindView:绑定组件

    返回值:无

    返回值意义:无

    作用:PopMenu的构造方法,绑定到某组件上

  

   public void  getMenuInflater()

    参数:无

    返回值:MenuInflater

    返回值意义:获取MenuInflater , 使用该对象对menu文件实例化

    作用;获取MenuInflater对象,使用该对象对menu文件实例化

  

  MenuInflater

介绍

  Menu文件专门实例化类

 

方法

 

  public View inflate( int menuId , popMenu.getMenu() )

     参数

      int menuId:menu文件的id值

      popMenu.getMenu():固定写法

    返回值:View

    返回值意义:将Menu资源文件实例化

    作用:将menu资源文件实例化

 

使用

  PopMenu是Android原始组件,使用实例化生成。有四个重要参数,上下文,绑定组件,资源文件,popMenu.getMenu()

  

 PopupMenu popupMenu = new PopupMenu(Home4.this,txtMenu);
 popupMenu.getMenuInflater().inflate(R.menu.popmenu2,popupMenu.getMenu());
 popupMenu.show();

 

        

posted @ 2021-09-06 14:06  remix_alone  阅读(187)  评论(0)    收藏  举报