Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Vince Varga
Vince Varga
15,282 Points

Add icon in the Action Bar using Support Libraries.

I had to add an icon in the Action Bar when using support libraries.

The solution was not trivial for me, so I am going to leave the solution here, if someone ever needs it in the future.

Vince Varga
Vince Varga
15,282 Points

Instead of android:showAsAction, simply use app:showAsAction

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      app="http://schemas.android.com/apk/res-auto" >

    <item android:id="@+id/action_camera"
          android:icon="@drawable/ic_action_camera"
          android:title="@string/action_camera_label"
          app:showAsAction="always"  />
    ...
</menu>

2 Answers

Nir Benjano
Nir Benjano
11,074 Points

The problem is with the support lib v7. In v7 you have to use a custom prefix (app:showAsAction). In v4 you can use android:showAsAction as the video. You should change the build.gradle:

  • target sdk to 19
  • compileSdkVersion to 19
  • compile 'com.android.support:-v7:19.1.0' ---> 'com.android.support:-v4:19.1.0'

I wish it helps

Andre Colares
Andre Colares
5,437 Points

Here is the main.xml for correct function at Android Studio 1.4

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:yourapp="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/action_edit_friends"
          android:title="@string/menu_edit_friends_label"></item>

    <item android:id="@+id/action_logout"
          android:title="@string/menu_logout_label"></item>

    <item android:id="@+id/action_camera"
          android:icon="@drawable/ic_action_camera"
          android:title="@string/menu_camera_label"
          yourapp:showAsAction="ifRoom"
          ></item>

</menu>