خرید بک لینک

Vote count: 0

By default I set the visibility to false by using following code.

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_items, menu);
       menu.findItem(R.id.action_share).setVisible(false);
        retu true;
    }

Now how can I make it visible again when user clicks a button in my activity.

asked 8 mins ago

2 Answers

Vote count: 0

In your onCreateOptionsMenu:

public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_items, menu);
       if (hideIcon){
          menu.findItem(R.id.action_share).setVisible(false);
       }else{
          menu.findItem(R.id.action_share).setVisible(true);
       }
        retu true;
    }

In method where you want to show/hide the icon, just set the boolean hideIcon to true or false and call :

invalidateOptionsMenu();

to refresh the menu.

answered 3 mins ago

Vote count: 0

get the instance of that menu item, and you can set its item Visibility every time.

        Menu mMenu;
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
           getMenuInflater().inflate(R.menu.menu_items, menu);
           mMenu = menu;
           mMenu.findItem(R.id.action_share).setVisible(false);
           retu true;
        }

//somewhere else

mMenu.findItem(R.id.action_share).setVisible(true);

answered 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 11 خرداد 1395 ساعت: 17:53

صفحه بندی