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 trial

Android Build a Self-Destructing Message Android App Capturing Photos and Videos Adding a Camera Button in the Action Bar

Joseph Karanja
Joseph Karanja
169 Points

Camera 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

Hello,

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
Joseph Karanja
169 Points

Hi 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
Slava Fleer
6,086 Points

HI, James. I also trying to do same thing, and it is not works no with @drawable neither with @mipmap. Any sujestions?

public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {

<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/action_logout"
          android:title="@string/action_logout"
          android:orderInCategory="200"
          app:showAsAction="never"/>

      <item android:id="@+id/action_edit_bodies"
            android:title="Edit Buddies"
            android:icon="@mipmap/ic_action_group"
            android:orderInCategory="100"
            app:showAsAction="never"/>
</menu>

Hello,

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
Slava Fleer
6,086 Points

no, 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.

The 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
Slava Fleer
6,086 Points

the name is right, cause it working with always. but again it is shown in action bar instead overflow menu.

Its 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
Slava Fleer
6,086 Points

yea. Sorry, missed with topic. Just re read it =).