android option menu with icon

前端 未结 9 1088
借酒劲吻你
借酒劲吻你 2021-02-05 08:36

How to show icon with option menu.I have tried the following code but my option menu is without image icon.I am using android version 4.0 for developing app.

Jav

9条回答
  •  别跟我提以往
    2021-02-05 09:01

    You Can try Following this Link.

    Check this out and tell me if it worked or not.

    Or you can do some thing like this.
    Create menu.xml

    
    
          
          
           
    
    

    And now you will be able to set ICON on menu

    Now in CreateOptionMenu

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

    And to access that menu.

    public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
          case R.id.next:
                Toast.makeText(this, "You have chosen the " + getResources().getString(R.string.next) + " menu option",
                            Toast.LENGTH_SHORT).show();
                return true;
          …
          default:
                return super.onOptionsItemSelected(item);
          }
       }
    

提交回复
热议问题