简体   繁体   中英

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);

您可以添加一个新资源,并使其在其他屏幕上不可见,并使我在所需的屏幕上可见。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM