aleixrr
aleixrr

Reputation: 489

Add Action Bar Menu Item Programatically

I want to programmatically set a new menu item on the right if the user is in a defined screen, but only if it's in this screen, not on another.

How can I do this without setting a new menu resource? In this class I'm actually changing my left menu item like that.

setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
getSupportActionBar().setHomeAsUpIndicator(ContextCompat.getDrawable(this,R.drawable.ic_back));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);

Upvotes: 0

Views: 80

Answers (1)

Alexander Smityuk
Alexander Smityuk

Reputation: 26

You can add a new recource and make it invisable on other screens and make I visable on the screen you want.

Upvotes: 1

Related Questions