Implementing an option menu in Android Studio

后端 未结 4 1807
名媛妹妹
名媛妹妹 2021-02-14 02:02

How do I implement an option menu in my android application? I tried code from Android Developer but I get errors. Such as these: Element menu must be declared.

4条回答
  •  耶瑟儿~
    2021-02-14 02:29

    You need to create a menu folder in the res directory and in the menu directory create file named my_menu.xml. In that file write these lines:

    
    
    
    
    
    

    Then in your Activity, do this:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.my_menu, menu);
        return true;
    }
    

提交回复
热议问题