Android toolbar menu is not showing
up vote
24
down vote
favorite
I'm trying to add a menu to the ToolBar.
onCreateOptionsMenu
method of my Activity
is called, but no menu appears.
This is dashboard.xml (from menu folder)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@drawable/ic_drawer"
android:title="@string/menu_scan_qr"
app:showAsAction="always" />
</menu>
NOTE: icon of this menu is darker than the background color of the action bar, so it should be visible.
Inflating menu in Activity:
public class DashboardActivity extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return true;
}
And the main theme for the application:
<style name="Theme.Application.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@android:color/white</item>
<item name="colorPrimaryDark">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/Theme.Application.DrawerArrowStyle</item>
<item name="android:textColorSecondary">@android:color/darker_gray</item>
</style>
Why onCreateOptionsMenu
is called but menu doesn't appears. I'm using appcompat-v7:21.0.3
EDIT:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentViewId());
toolbar = (Toolbar) findViewById(R.id.tool_bar);
if (toolbar == null) {
throw new Error("Can't find tool bar, did you forget to add it in Activity layout file?");
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
android android-actionbar-compat
add a comment |
up vote
24
down vote
favorite
I'm trying to add a menu to the ToolBar.
onCreateOptionsMenu
method of my Activity
is called, but no menu appears.
This is dashboard.xml (from menu folder)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@drawable/ic_drawer"
android:title="@string/menu_scan_qr"
app:showAsAction="always" />
</menu>
NOTE: icon of this menu is darker than the background color of the action bar, so it should be visible.
Inflating menu in Activity:
public class DashboardActivity extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return true;
}
And the main theme for the application:
<style name="Theme.Application.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@android:color/white</item>
<item name="colorPrimaryDark">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/Theme.Application.DrawerArrowStyle</item>
<item name="android:textColorSecondary">@android:color/darker_gray</item>
</style>
Why onCreateOptionsMenu
is called but menu doesn't appears. I'm using appcompat-v7:21.0.3
EDIT:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentViewId());
toolbar = (Toolbar) findViewById(R.id.tool_bar);
if (toolbar == null) {
throw new Error("Can't find tool bar, did you forget to add it in Activity layout file?");
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
android android-actionbar-compat
Try to addandroid:orderInCategory="100"
in your xml item
– Skizo-ozᴉʞS
Feb 4 '15 at 9:37
1
What does your Activity's layout look like? Does it contain a Toolbar view and are you setting it to the activity via setSupportActionBar(toolbar)?
– npace
Feb 4 '15 at 9:39
I'm using setSupportActionBar(toolbar) after inflating it from activity layout file.
– Procurares
Feb 4 '15 at 9:43
Joan, orderInCategory doesn't help
– Procurares
Feb 4 '15 at 9:44
Try to replacereturn(super.onCreateOptionsMenu(menu));
instead of return true;
– Skizo-ozᴉʞS
Feb 4 '15 at 9:45
add a comment |
up vote
24
down vote
favorite
up vote
24
down vote
favorite
I'm trying to add a menu to the ToolBar.
onCreateOptionsMenu
method of my Activity
is called, but no menu appears.
This is dashboard.xml (from menu folder)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@drawable/ic_drawer"
android:title="@string/menu_scan_qr"
app:showAsAction="always" />
</menu>
NOTE: icon of this menu is darker than the background color of the action bar, so it should be visible.
Inflating menu in Activity:
public class DashboardActivity extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return true;
}
And the main theme for the application:
<style name="Theme.Application.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@android:color/white</item>
<item name="colorPrimaryDark">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/Theme.Application.DrawerArrowStyle</item>
<item name="android:textColorSecondary">@android:color/darker_gray</item>
</style>
Why onCreateOptionsMenu
is called but menu doesn't appears. I'm using appcompat-v7:21.0.3
EDIT:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentViewId());
toolbar = (Toolbar) findViewById(R.id.tool_bar);
if (toolbar == null) {
throw new Error("Can't find tool bar, did you forget to add it in Activity layout file?");
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
android android-actionbar-compat
I'm trying to add a menu to the ToolBar.
onCreateOptionsMenu
method of my Activity
is called, but no menu appears.
This is dashboard.xml (from menu folder)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@drawable/ic_drawer"
android:title="@string/menu_scan_qr"
app:showAsAction="always" />
</menu>
NOTE: icon of this menu is darker than the background color of the action bar, so it should be visible.
Inflating menu in Activity:
public class DashboardActivity extends ActionBarActivity {
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return true;
}
And the main theme for the application:
<style name="Theme.Application.Base" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@android:color/white</item>
<item name="colorPrimaryDark">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">@style/Theme.Application.DrawerArrowStyle</item>
<item name="android:textColorSecondary">@android:color/darker_gray</item>
</style>
Why onCreateOptionsMenu
is called but menu doesn't appears. I'm using appcompat-v7:21.0.3
EDIT:
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentViewId());
toolbar = (Toolbar) findViewById(R.id.tool_bar);
if (toolbar == null) {
throw new Error("Can't find tool bar, did you forget to add it in Activity layout file?");
}
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
android android-actionbar-compat
android android-actionbar-compat
edited Feb 4 '15 at 9:47
asked Feb 4 '15 at 9:33
Procurares
1,06041430
1,06041430
Try to addandroid:orderInCategory="100"
in your xml item
– Skizo-ozᴉʞS
Feb 4 '15 at 9:37
1
What does your Activity's layout look like? Does it contain a Toolbar view and are you setting it to the activity via setSupportActionBar(toolbar)?
– npace
Feb 4 '15 at 9:39
I'm using setSupportActionBar(toolbar) after inflating it from activity layout file.
– Procurares
Feb 4 '15 at 9:43
Joan, orderInCategory doesn't help
– Procurares
Feb 4 '15 at 9:44
Try to replacereturn(super.onCreateOptionsMenu(menu));
instead of return true;
– Skizo-ozᴉʞS
Feb 4 '15 at 9:45
add a comment |
Try to addandroid:orderInCategory="100"
in your xml item
– Skizo-ozᴉʞS
Feb 4 '15 at 9:37
1
What does your Activity's layout look like? Does it contain a Toolbar view and are you setting it to the activity via setSupportActionBar(toolbar)?
– npace
Feb 4 '15 at 9:39
I'm using setSupportActionBar(toolbar) after inflating it from activity layout file.
– Procurares
Feb 4 '15 at 9:43
Joan, orderInCategory doesn't help
– Procurares
Feb 4 '15 at 9:44
Try to replacereturn(super.onCreateOptionsMenu(menu));
instead of return true;
– Skizo-ozᴉʞS
Feb 4 '15 at 9:45
Try to add
android:orderInCategory="100"
in your xml item– Skizo-ozᴉʞS
Feb 4 '15 at 9:37
Try to add
android:orderInCategory="100"
in your xml item– Skizo-ozᴉʞS
Feb 4 '15 at 9:37
1
1
What does your Activity's layout look like? Does it contain a Toolbar view and are you setting it to the activity via setSupportActionBar(toolbar)?
– npace
Feb 4 '15 at 9:39
What does your Activity's layout look like? Does it contain a Toolbar view and are you setting it to the activity via setSupportActionBar(toolbar)?
– npace
Feb 4 '15 at 9:39
I'm using setSupportActionBar(toolbar) after inflating it from activity layout file.
– Procurares
Feb 4 '15 at 9:43
I'm using setSupportActionBar(toolbar) after inflating it from activity layout file.
– Procurares
Feb 4 '15 at 9:43
Joan, orderInCategory doesn't help
– Procurares
Feb 4 '15 at 9:44
Joan, orderInCategory doesn't help
– Procurares
Feb 4 '15 at 9:44
Try to replace
return(super.onCreateOptionsMenu(menu));
instead of return true;– Skizo-ozᴉʞS
Feb 4 '15 at 9:45
Try to replace
return(super.onCreateOptionsMenu(menu));
instead of return true;– Skizo-ozᴉʞS
Feb 4 '15 at 9:45
add a comment |
14 Answers
14
active
oldest
votes
up vote
26
down vote
I was also facing the same problem, but the actual error was, i forgot to introduce toolbar in java activity
under AppCompactActivity
, under on create method define your toolbar by id and call setSupportActionBar(ToolBar);
Example is bellow:
public class secondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
2
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
add a comment |
up vote
25
down vote
accepted
I'm not sure why, but when i place everything related menu inflating in onPrepareOptionsMenu method, everything works fine.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
It does work indeed, but why? What is the purpose ofinflate()
? The official documentation doesn't even mention this.
– Jan Šimek
Apr 6 '16 at 19:42
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
|
show 1 more comment
up vote
8
down vote
Try the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.lolipoptest.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
and the Java 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.main, menu);
return true;
}
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
add a comment |
up vote
6
down vote
Do you have Toolbar in your dashboard layout ?. Call setSupportActionBar(toolbar) in your activity. Use Theme.AppCompat.NoActionBar theme for the activities (If you are using toolbar in it)
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
public class DashboardActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Check your styles.
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="AppTheme" >
</style>
<color name="light">#FFBB33</color>
<color name="colorPrimary">#FFBB33</color>
<color name="textColorPrimary">#FFBB33</color>
<color name="colorPrimaryDark">#FF8800</color>
<color name="colorAccent">#ff9977</color>
<color name="white">#ffffff</color>
</resources>
Check your layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:titleMarginStart="20dp"
android:paddingRight="10dp"
android:background="@color/colorPrimaryDark"
app:theme="@style/ToolbarTheme" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Hello Toolbar" />
</LinearLayout>
Add theme in your activity in manifest
android:theme="@style/AppTheme"
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Thank you so much
– user3930824
Sep 12 '15 at 8:02
add a comment |
up vote
2
down vote
Try changing:
....
xmlns:app="http://schemas.android.com/apk/res-auto" >
....
app:showAsAction="ifRoom"
to:
....
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
....
yourapp:showAsAction="ifRoom"
https://developer.android.com/training/basics/actionbar/adding-buttons.html
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
1
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
add a comment |
up vote
1
down vote
If you're using a Toolbar
you need to set it as the support action bar in onCreate
:
setSupportActionBar(toolbar);
add a comment |
up vote
1
down vote
you guys are doing it wrong. you need to inflate your menu in onCreateOptionsMenu of the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mymenu, menu);
return super.onCreateOptionsMenu(menu);
}
add a comment |
up vote
1
down vote
If you are inflating your menu from a fragment, e.g. by overriding onCreateOptionsMenu
method, make sure to call setHasOptionsMenu(true)
in onCreateView
of your fragment
add a comment |
up vote
0
down vote
The issue is resolved when I changed it to app:showAsAction to android:showAsAction
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
add a comment |
up vote
0
down vote
In my case it was stupid simple.
My toolbar was a child of AppBarLayout, and for some reason, when I was setting a Toolbar with Constraint layout, Toolbar's layout_width xml parameter was set to 0dp. So the toolbar was there, but invisible... (>_<)
So, if nothing from above helped you, just check "layout_width" and "layout_height" parameters.
Hope this will save someone's time :)
add a comment |
up vote
0
down vote
Add Icon you want under mipmap folder
Create menu_analysis.xml(under menu folder values.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@mipmap/ic_menu_options"
android:title=""
app:showAsAction="always" />
</menu>
Now onPrepareOptionMenu under your Java class
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_analysis, menu);
return super.onCreateOptionsMenu(menu);
}
add a comment |
up vote
0
down vote
Although the accepted answer does work, it causes my menu items rendered twice. As I've just worked around this, try somethings as:
- remember to
return true;
instead ofsuper.onCreateOptionsMenu(menu);
- remember to set support action bar
setSupportActionBar(findViewById(R.id.toolbar))
- You might want to turn off default app title if you use customized toolbar:
getSupportActionBar().setDisplayShowTitleEnabled(false)
add a comment |
up vote
0
down vote
Use setSupportActionBar(toolbar) in onCreate Method.
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
add a comment |
up vote
0
down vote
I had written like,
MenuInflater(this).inflate(R.menu.my_menu, menu)
But, I changed the code like,
menuInflater.inflate(R.menu.my_menu, menu)
and it worked!
(I'm using kotlin and this code was written in Activity)
add a comment |
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
26
down vote
I was also facing the same problem, but the actual error was, i forgot to introduce toolbar in java activity
under AppCompactActivity
, under on create method define your toolbar by id and call setSupportActionBar(ToolBar);
Example is bellow:
public class secondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
2
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
add a comment |
up vote
26
down vote
I was also facing the same problem, but the actual error was, i forgot to introduce toolbar in java activity
under AppCompactActivity
, under on create method define your toolbar by id and call setSupportActionBar(ToolBar);
Example is bellow:
public class secondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
2
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
add a comment |
up vote
26
down vote
up vote
26
down vote
I was also facing the same problem, but the actual error was, i forgot to introduce toolbar in java activity
under AppCompactActivity
, under on create method define your toolbar by id and call setSupportActionBar(ToolBar);
Example is bellow:
public class secondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
I was also facing the same problem, but the actual error was, i forgot to introduce toolbar in java activity
under AppCompactActivity
, under on create method define your toolbar by id and call setSupportActionBar(ToolBar);
Example is bellow:
public class secondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
edited Sep 15 '16 at 12:27
cylon
5611826
5611826
answered Mar 17 '16 at 11:44
Shubham
532614
532614
2
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
add a comment |
2
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
2
2
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
it is correct. i had the same problem. i did you said and it solved
– cimenmus
Apr 1 '16 at 16:55
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
i had everything set up but didnt use setSupportActionBar(ToolBar); introducing setSupportActionBar made the action button show up
– antroid
Jun 21 '17 at 12:51
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
Thanks you save my hours :)
– sumit mehra
Sep 27 '17 at 6:33
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
ya it worked fine , thank you man
– Mosa
Jan 8 at 13:14
add a comment |
up vote
25
down vote
accepted
I'm not sure why, but when i place everything related menu inflating in onPrepareOptionsMenu method, everything works fine.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
It does work indeed, but why? What is the purpose ofinflate()
? The official documentation doesn't even mention this.
– Jan Šimek
Apr 6 '16 at 19:42
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
|
show 1 more comment
up vote
25
down vote
accepted
I'm not sure why, but when i place everything related menu inflating in onPrepareOptionsMenu method, everything works fine.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
It does work indeed, but why? What is the purpose ofinflate()
? The official documentation doesn't even mention this.
– Jan Šimek
Apr 6 '16 at 19:42
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
|
show 1 more comment
up vote
25
down vote
accepted
up vote
25
down vote
accepted
I'm not sure why, but when i place everything related menu inflating in onPrepareOptionsMenu method, everything works fine.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
I'm not sure why, but when i place everything related menu inflating in onPrepareOptionsMenu method, everything works fine.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
answered Feb 4 '15 at 10:09
Procurares
1,06041430
1,06041430
It does work indeed, but why? What is the purpose ofinflate()
? The official documentation doesn't even mention this.
– Jan Šimek
Apr 6 '16 at 19:42
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
|
show 1 more comment
It does work indeed, but why? What is the purpose ofinflate()
? The official documentation doesn't even mention this.
– Jan Šimek
Apr 6 '16 at 19:42
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
It does work indeed, but why? What is the purpose of
inflate()
? The official documentation doesn't even mention this.– Jan Šimek
Apr 6 '16 at 19:42
It does work indeed, but why? What is the purpose of
inflate()
? The official documentation doesn't even mention this.– Jan Šimek
Apr 6 '16 at 19:42
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
It could be just overlapping color problem. If your toolbar is black color and the menu text is also in black color, you can't really see it. Even overflow menu icon was also black :D (It happened in my case). Further dismay- if there are only one or two menu options, even menu button does not seem to work (because menu is already present in toolbar)
– Vinay Bhargav
Apr 27 '16 at 12:48
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
it will continuously create when ever it is clicked,So use this @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }
– Adnan Ali
Jun 1 '16 at 19:15
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
thanks Bro it was surprisingly acting. fabulous +1 for you
– Dinesh
Sep 19 '16 at 19:33
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
Do you really call super.onCreateOptionsMenu(menu) and not super.onPrepareOptionsMenu(menu)?
– kingston
Feb 12 '17 at 10:28
|
show 1 more comment
up vote
8
down vote
Try the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.lolipoptest.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
and the Java 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.main, menu);
return true;
}
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
add a comment |
up vote
8
down vote
Try the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.lolipoptest.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
and the Java 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.main, menu);
return true;
}
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
add a comment |
up vote
8
down vote
up vote
8
down vote
Try the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.lolipoptest.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
and the Java 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.main, menu);
return true;
}
Try the following:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.example.lolipoptest.MainActivity" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
and the Java 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.main, menu);
return true;
}
edited May 10 '17 at 13:31
Axe
4,79032237
4,79032237
answered Feb 4 '15 at 9:45
Akash
695513
695513
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
add a comment |
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Just tried it doesn't help
– Procurares
Feb 4 '15 at 9:49
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
Check this one stackoverflow.com/questions/26638089/…
– Akash
Feb 4 '15 at 9:59
add a comment |
up vote
6
down vote
Do you have Toolbar in your dashboard layout ?. Call setSupportActionBar(toolbar) in your activity. Use Theme.AppCompat.NoActionBar theme for the activities (If you are using toolbar in it)
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
public class DashboardActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Check your styles.
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="AppTheme" >
</style>
<color name="light">#FFBB33</color>
<color name="colorPrimary">#FFBB33</color>
<color name="textColorPrimary">#FFBB33</color>
<color name="colorPrimaryDark">#FF8800</color>
<color name="colorAccent">#ff9977</color>
<color name="white">#ffffff</color>
</resources>
Check your layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:titleMarginStart="20dp"
android:paddingRight="10dp"
android:background="@color/colorPrimaryDark"
app:theme="@style/ToolbarTheme" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Hello Toolbar" />
</LinearLayout>
Add theme in your activity in manifest
android:theme="@style/AppTheme"
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Thank you so much
– user3930824
Sep 12 '15 at 8:02
add a comment |
up vote
6
down vote
Do you have Toolbar in your dashboard layout ?. Call setSupportActionBar(toolbar) in your activity. Use Theme.AppCompat.NoActionBar theme for the activities (If you are using toolbar in it)
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
public class DashboardActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Check your styles.
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="AppTheme" >
</style>
<color name="light">#FFBB33</color>
<color name="colorPrimary">#FFBB33</color>
<color name="textColorPrimary">#FFBB33</color>
<color name="colorPrimaryDark">#FF8800</color>
<color name="colorAccent">#ff9977</color>
<color name="white">#ffffff</color>
</resources>
Check your layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:titleMarginStart="20dp"
android:paddingRight="10dp"
android:background="@color/colorPrimaryDark"
app:theme="@style/ToolbarTheme" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Hello Toolbar" />
</LinearLayout>
Add theme in your activity in manifest
android:theme="@style/AppTheme"
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Thank you so much
– user3930824
Sep 12 '15 at 8:02
add a comment |
up vote
6
down vote
up vote
6
down vote
Do you have Toolbar in your dashboard layout ?. Call setSupportActionBar(toolbar) in your activity. Use Theme.AppCompat.NoActionBar theme for the activities (If you are using toolbar in it)
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
public class DashboardActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Check your styles.
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="AppTheme" >
</style>
<color name="light">#FFBB33</color>
<color name="colorPrimary">#FFBB33</color>
<color name="textColorPrimary">#FFBB33</color>
<color name="colorPrimaryDark">#FF8800</color>
<color name="colorAccent">#ff9977</color>
<color name="white">#ffffff</color>
</resources>
Check your layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:titleMarginStart="20dp"
android:paddingRight="10dp"
android:background="@color/colorPrimaryDark"
app:theme="@style/ToolbarTheme" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Hello Toolbar" />
</LinearLayout>
Add theme in your activity in manifest
android:theme="@style/AppTheme"
Do you have Toolbar in your dashboard layout ?. Call setSupportActionBar(toolbar) in your activity. Use Theme.AppCompat.NoActionBar theme for the activities (If you are using toolbar in it)
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
public class DashboardActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Check your styles.
<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="AppTheme" >
</style>
<color name="light">#FFBB33</color>
<color name="colorPrimary">#FFBB33</color>
<color name="textColorPrimary">#FFBB33</color>
<color name="colorPrimaryDark">#FF8800</color>
<color name="colorAccent">#ff9977</color>
<color name="white">#ffffff</color>
</resources>
Check your layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:titleMarginStart="20dp"
android:paddingRight="10dp"
android:background="@color/colorPrimaryDark"
app:theme="@style/ToolbarTheme" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Hello Toolbar" />
</LinearLayout>
Add theme in your activity in manifest
android:theme="@style/AppTheme"
edited Feb 12 '17 at 10:29
kingston
5,62074380
5,62074380
answered Feb 4 '15 at 9:44
Sujith
4,71511734
4,71511734
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Thank you so much
– user3930824
Sep 12 '15 at 8:02
add a comment |
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Thank you so much
– user3930824
Sep 12 '15 at 8:02
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
I updated topic and added here onCreate method
– Procurares
Feb 4 '15 at 9:48
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Not entirely true, the library adds the toolbar if not present and the right theme is used
– pablisco
Feb 4 '15 at 9:51
Thank you so much
– user3930824
Sep 12 '15 at 8:02
Thank you so much
– user3930824
Sep 12 '15 at 8:02
add a comment |
up vote
2
down vote
Try changing:
....
xmlns:app="http://schemas.android.com/apk/res-auto" >
....
app:showAsAction="ifRoom"
to:
....
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
....
yourapp:showAsAction="ifRoom"
https://developer.android.com/training/basics/actionbar/adding-buttons.html
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
1
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
add a comment |
up vote
2
down vote
Try changing:
....
xmlns:app="http://schemas.android.com/apk/res-auto" >
....
app:showAsAction="ifRoom"
to:
....
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
....
yourapp:showAsAction="ifRoom"
https://developer.android.com/training/basics/actionbar/adding-buttons.html
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
1
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
add a comment |
up vote
2
down vote
up vote
2
down vote
Try changing:
....
xmlns:app="http://schemas.android.com/apk/res-auto" >
....
app:showAsAction="ifRoom"
to:
....
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
....
yourapp:showAsAction="ifRoom"
https://developer.android.com/training/basics/actionbar/adding-buttons.html
Try changing:
....
xmlns:app="http://schemas.android.com/apk/res-auto" >
....
app:showAsAction="ifRoom"
to:
....
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
....
yourapp:showAsAction="ifRoom"
https://developer.android.com/training/basics/actionbar/adding-buttons.html
edited Feb 4 '15 at 10:13
answered Feb 4 '15 at 9:54
Yvette Colomb♦
19.8k1369107
19.8k1369107
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
1
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
add a comment |
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
1
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
This gives me exception: "This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead."
– Procurares
Feb 4 '15 at 9:59
1
1
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
thanks its work for me
– Jatin Patel
Sep 12 '16 at 5:15
add a comment |
up vote
1
down vote
If you're using a Toolbar
you need to set it as the support action bar in onCreate
:
setSupportActionBar(toolbar);
add a comment |
up vote
1
down vote
If you're using a Toolbar
you need to set it as the support action bar in onCreate
:
setSupportActionBar(toolbar);
add a comment |
up vote
1
down vote
up vote
1
down vote
If you're using a Toolbar
you need to set it as the support action bar in onCreate
:
setSupportActionBar(toolbar);
If you're using a Toolbar
you need to set it as the support action bar in onCreate
:
setSupportActionBar(toolbar);
answered Nov 19 '15 at 14:45
Leon
1,5531732
1,5531732
add a comment |
add a comment |
up vote
1
down vote
you guys are doing it wrong. you need to inflate your menu in onCreateOptionsMenu of the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mymenu, menu);
return super.onCreateOptionsMenu(menu);
}
add a comment |
up vote
1
down vote
you guys are doing it wrong. you need to inflate your menu in onCreateOptionsMenu of the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mymenu, menu);
return super.onCreateOptionsMenu(menu);
}
add a comment |
up vote
1
down vote
up vote
1
down vote
you guys are doing it wrong. you need to inflate your menu in onCreateOptionsMenu of the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mymenu, menu);
return super.onCreateOptionsMenu(menu);
}
you guys are doing it wrong. you need to inflate your menu in onCreateOptionsMenu of the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.mymenu, menu);
return super.onCreateOptionsMenu(menu);
}
answered Jun 23 '17 at 14:55
j2emanue
20.8k22135244
20.8k22135244
add a comment |
add a comment |
up vote
1
down vote
If you are inflating your menu from a fragment, e.g. by overriding onCreateOptionsMenu
method, make sure to call setHasOptionsMenu(true)
in onCreateView
of your fragment
add a comment |
up vote
1
down vote
If you are inflating your menu from a fragment, e.g. by overriding onCreateOptionsMenu
method, make sure to call setHasOptionsMenu(true)
in onCreateView
of your fragment
add a comment |
up vote
1
down vote
up vote
1
down vote
If you are inflating your menu from a fragment, e.g. by overriding onCreateOptionsMenu
method, make sure to call setHasOptionsMenu(true)
in onCreateView
of your fragment
If you are inflating your menu from a fragment, e.g. by overriding onCreateOptionsMenu
method, make sure to call setHasOptionsMenu(true)
in onCreateView
of your fragment
answered Aug 17 '17 at 11:06
egorikem
638616
638616
add a comment |
add a comment |
up vote
0
down vote
The issue is resolved when I changed it to app:showAsAction to android:showAsAction
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
add a comment |
up vote
0
down vote
The issue is resolved when I changed it to app:showAsAction to android:showAsAction
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
add a comment |
up vote
0
down vote
up vote
0
down vote
The issue is resolved when I changed it to app:showAsAction to android:showAsAction
The issue is resolved when I changed it to app:showAsAction to android:showAsAction
answered Jul 2 '17 at 23:21
messi
6124
6124
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
add a comment |
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
You may want to added the code chuck with the fix.
– M.Qasim
Jul 2 '17 at 23:44
add a comment |
up vote
0
down vote
In my case it was stupid simple.
My toolbar was a child of AppBarLayout, and for some reason, when I was setting a Toolbar with Constraint layout, Toolbar's layout_width xml parameter was set to 0dp. So the toolbar was there, but invisible... (>_<)
So, if nothing from above helped you, just check "layout_width" and "layout_height" parameters.
Hope this will save someone's time :)
add a comment |
up vote
0
down vote
In my case it was stupid simple.
My toolbar was a child of AppBarLayout, and for some reason, when I was setting a Toolbar with Constraint layout, Toolbar's layout_width xml parameter was set to 0dp. So the toolbar was there, but invisible... (>_<)
So, if nothing from above helped you, just check "layout_width" and "layout_height" parameters.
Hope this will save someone's time :)
add a comment |
up vote
0
down vote
up vote
0
down vote
In my case it was stupid simple.
My toolbar was a child of AppBarLayout, and for some reason, when I was setting a Toolbar with Constraint layout, Toolbar's layout_width xml parameter was set to 0dp. So the toolbar was there, but invisible... (>_<)
So, if nothing from above helped you, just check "layout_width" and "layout_height" parameters.
Hope this will save someone's time :)
In my case it was stupid simple.
My toolbar was a child of AppBarLayout, and for some reason, when I was setting a Toolbar with Constraint layout, Toolbar's layout_width xml parameter was set to 0dp. So the toolbar was there, but invisible... (>_<)
So, if nothing from above helped you, just check "layout_width" and "layout_height" parameters.
Hope this will save someone's time :)
answered Oct 6 '17 at 12:23
Elisey Rodriguez Moraga
666
666
add a comment |
add a comment |
up vote
0
down vote
Add Icon you want under mipmap folder
Create menu_analysis.xml(under menu folder values.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@mipmap/ic_menu_options"
android:title=""
app:showAsAction="always" />
</menu>
Now onPrepareOptionMenu under your Java class
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_analysis, menu);
return super.onCreateOptionsMenu(menu);
}
add a comment |
up vote
0
down vote
Add Icon you want under mipmap folder
Create menu_analysis.xml(under menu folder values.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@mipmap/ic_menu_options"
android:title=""
app:showAsAction="always" />
</menu>
Now onPrepareOptionMenu under your Java class
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_analysis, menu);
return super.onCreateOptionsMenu(menu);
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Add Icon you want under mipmap folder
Create menu_analysis.xml(under menu folder values.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@mipmap/ic_menu_options"
android:title=""
app:showAsAction="always" />
</menu>
Now onPrepareOptionMenu under your Java class
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_analysis, menu);
return super.onCreateOptionsMenu(menu);
}
Add Icon you want under mipmap folder
Create menu_analysis.xml(under menu folder values.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.app.android.ui.dashboard.DashboardActivity">
<item
android:id="@+id/action_scan_qr"
android:icon="@mipmap/ic_menu_options"
android:title=""
app:showAsAction="always" />
</menu>
Now onPrepareOptionMenu under your Java class
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.menu_analysis, menu);
return super.onCreateOptionsMenu(menu);
}
edited Feb 26 at 13:00
Pragnesh Ghoda シ
6,95232038
6,95232038
answered Oct 30 '17 at 5:51
Tarit Ray
377417
377417
add a comment |
add a comment |
up vote
0
down vote
Although the accepted answer does work, it causes my menu items rendered twice. As I've just worked around this, try somethings as:
- remember to
return true;
instead ofsuper.onCreateOptionsMenu(menu);
- remember to set support action bar
setSupportActionBar(findViewById(R.id.toolbar))
- You might want to turn off default app title if you use customized toolbar:
getSupportActionBar().setDisplayShowTitleEnabled(false)
add a comment |
up vote
0
down vote
Although the accepted answer does work, it causes my menu items rendered twice. As I've just worked around this, try somethings as:
- remember to
return true;
instead ofsuper.onCreateOptionsMenu(menu);
- remember to set support action bar
setSupportActionBar(findViewById(R.id.toolbar))
- You might want to turn off default app title if you use customized toolbar:
getSupportActionBar().setDisplayShowTitleEnabled(false)
add a comment |
up vote
0
down vote
up vote
0
down vote
Although the accepted answer does work, it causes my menu items rendered twice. As I've just worked around this, try somethings as:
- remember to
return true;
instead ofsuper.onCreateOptionsMenu(menu);
- remember to set support action bar
setSupportActionBar(findViewById(R.id.toolbar))
- You might want to turn off default app title if you use customized toolbar:
getSupportActionBar().setDisplayShowTitleEnabled(false)
Although the accepted answer does work, it causes my menu items rendered twice. As I've just worked around this, try somethings as:
- remember to
return true;
instead ofsuper.onCreateOptionsMenu(menu);
- remember to set support action bar
setSupportActionBar(findViewById(R.id.toolbar))
- You might want to turn off default app title if you use customized toolbar:
getSupportActionBar().setDisplayShowTitleEnabled(false)
answered May 17 at 20:05
Lê Vũ Linh
213
213
add a comment |
add a comment |
up vote
0
down vote
Use setSupportActionBar(toolbar) in onCreate Method.
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
add a comment |
up vote
0
down vote
Use setSupportActionBar(toolbar) in onCreate Method.
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
add a comment |
up vote
0
down vote
up vote
0
down vote
Use setSupportActionBar(toolbar) in onCreate Method.
Use setSupportActionBar(toolbar) in onCreate Method.
answered Aug 17 at 6:21
Fahad Ali
63
63
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
add a comment |
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
kindly consider adding more information in your answer
– Inder
Aug 17 at 6:42
add a comment |
up vote
0
down vote
I had written like,
MenuInflater(this).inflate(R.menu.my_menu, menu)
But, I changed the code like,
menuInflater.inflate(R.menu.my_menu, menu)
and it worked!
(I'm using kotlin and this code was written in Activity)
add a comment |
up vote
0
down vote
I had written like,
MenuInflater(this).inflate(R.menu.my_menu, menu)
But, I changed the code like,
menuInflater.inflate(R.menu.my_menu, menu)
and it worked!
(I'm using kotlin and this code was written in Activity)
add a comment |
up vote
0
down vote
up vote
0
down vote
I had written like,
MenuInflater(this).inflate(R.menu.my_menu, menu)
But, I changed the code like,
menuInflater.inflate(R.menu.my_menu, menu)
and it worked!
(I'm using kotlin and this code was written in Activity)
I had written like,
MenuInflater(this).inflate(R.menu.my_menu, menu)
But, I changed the code like,
menuInflater.inflate(R.menu.my_menu, menu)
and it worked!
(I'm using kotlin and this code was written in Activity)
answered Nov 9 at 7:50
david
64112
64112
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28317905%2fandroid-toolbar-menu-is-not-showing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try to add
android:orderInCategory="100"
in your xml item– Skizo-ozᴉʞS
Feb 4 '15 at 9:37
1
What does your Activity's layout look like? Does it contain a Toolbar view and are you setting it to the activity via setSupportActionBar(toolbar)?
– npace
Feb 4 '15 at 9:39
I'm using setSupportActionBar(toolbar) after inflating it from activity layout file.
– Procurares
Feb 4 '15 at 9:43
Joan, orderInCategory doesn't help
– Procurares
Feb 4 '15 at 9:44
Try to replace
return(super.onCreateOptionsMenu(menu));
instead of return true;– Skizo-ozᴉʞS
Feb 4 '15 at 9:45