Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Karanja
169 PointsCamera icon in overflow menu instead of action, even after following all steps
i'm using android studio. Here is my code
<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=".MainActivity">
<item
android:id="@+id/menu_camera"
android:title="@string/menu_camera_label"
android:icon="@drawable/ic_action_camera"
app:showAsAction="ifRoom" />
</menu>
On the "showAsAction" i have tried "Always" and "ifRoom. None of them seem to work."With this, the camera option is in the overflow menu instead of actionbar. Any advise on how to get it on the action bar?
1 Answer
James Simshaw
28,738 PointsHello,
Is your activity extending ActionBarActivity? Also, is your icon stored in the drawables folders or the mipmap folders? Newer versions of Android Studio has a folder called mipmap that most of the icons are referenced from. Which is done via "@mipmap" instead of "@drawable".
Joseph Karanja
169 PointsJoseph Karanja
169 PointsHi James,
Thanks for replying.
I was able to fix it before i saw your reply. I switched to using a toolbar (appcompat) to replace the action bar, which i think is quite handy for my needs :) F.Y.I - I'm referencing the material in the tutorials to build my own app. About @mipmap, yeah, i saw that. So all icons are now referenced from there instead of @drawables?
Slava Fleer
6,086 PointsSlava Fleer
6,086 PointsHI, James. I also trying to do same thing, and it is not works no with @drawable neither with @mipmap. Any sujestions?
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsHello,
At first look, it looks like you are mixing XML and Java in one file, those should be kept seperate. If that's just a copy and paste error, then the other thing I see is that you're using app:showAsAction="never", that setting means that it will never attempt to show an icon and will always just include it in the overflow menu. If you want something to always show, you need to use "always".
Slava Fleer
6,086 PointsSlava Fleer
6,086 Pointsno, it was just to show the extends to you =)
When using always in showAsAction it would be shown in action bar, and I want to see Icon and not Title in menu that opens after pressing on 3 dots. I tried all possible variations of showAsAction, but neither was doing what i want.
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsThe only other things I can think of immediately is that your icon isn't named ic_action_group.png and to verify where it is located.
Slava Fleer
6,086 PointsSlava Fleer
6,086 Pointsthe name is right, cause it working with always. but again it is shown in action bar instead overflow menu.
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsIts sounding like your issuse is different from that of this post. In order to not confuse others who come looking to this post for help, can you start a new thread that we can discuss your problem in? Also, when you create that new thread, can you post in detail what you are wanting to happen?
Slava Fleer
6,086 PointsSlava Fleer
6,086 Pointsyea. Sorry, missed with topic. Just re read it =).