I am using theme of main activity , but option menu is not showing . please tell how to show option menu with this theme, please tell me about this issue
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
This is my java code . it will fine whan I change the theme to other like dark action bar please tell me what can I do
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_setting, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
// write your code here
return true;
case 2:
// write your code here
return true;
case 3:
// write your code here
return true;
case 4:
// write your code here
return true;
case 5:
// write your code here
return true;
case 6:
// write your code here
return true;
default:
return super.onOptionsItemSelected(item);
}
}
this is my xml
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/Timer"
android:title="@string/timer"/>
<item
android:id="@+id/friends"
android:title="@string/night_mode"/>
<item
android:id="@+id/about"
android:title="@string/quiz_type"/>
</menu>
Because you're using NoActionBar
theme, so there's no action bar in your activity
. In order to show your menu in your activity, the best method is adding Toolbar
as your actionbar as this Google Guide - Set up the app bar :
// add toolbar to your layout xml
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
// set toolbar as actionbar in your activity
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
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.