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 trialVince Varga
15,338 PointsAdd 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.
2 Answers
Nir Benjano
11,074 PointsThe 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
5,437 PointsHere 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>
Vince Varga
15,338 PointsVince Varga
15,338 PointsInstead of
android:showAsAction
, simply useapp:showAsAction