I have use Fragments so, I had to use theme NoActionBar, but when I inflate option menu it does not showing anything.How to resolve this? Here is my Code:
MainActivity.java
> @Override
> public boolean onCreateOptionsMenu(Menu menu){
> MenuInflater inflater =getMenuInflater();
> inflater.inflate(R.menu.options,menu);
> return super.onCreateOptionsMenu(menu);
> }
> @Override
> public boolean onOptionsItemSelected(MenuItem item){
> switch(item.getItemId()){
> case R.id.item1 :
> Intent box = new Intent(MainActivity.this,Developer.class);
> startActivity(box);
> break;
> }
> return true;
> }
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
options.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Developer" android:id="@+id/item1"/>
</menu>
You can add menu right to your toolbar using android.support.v7.widget.Toolbar#inflateMenu
method. This is example it kotlin
with(toolbar) {
inflateMenu(R.menu.menu_account_detail)
setOnMenuItemClickListener {
if (it.itemId == R.id.search) {
doSearch()
}
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.