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

Vince Varga
Vince Varga
15,283 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,283 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>