17

I am building an Android app and want to have a button always visible on the actionBar. I followed this guide and others, but none of them seem to solve my problem (although they are very close I guess...).

I have the package "app" and use app:showAsAction="always". No error is shown, but no button on the bar as well. When I change it to android:showAsAction="always" the button appears on the bar, but AndroidStudio tells me I should go for "app:showAsAction with appCompat...".

I have a custom theme with parent="@android:style/Theme.Holo.Light.DarkActionBar"> and for the bar itself: parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">.

Should I change something and get app:showAsAction working, or ignore AndroidStudio error message and go for android:showAsAction?

3yakuya
  • 2,622
  • 4
  • 25
  • 40
  • 1
    if you use appcompat the you should use app:showAsAction to support lowerversions, if you use android:showAsAction then it wont show up on lower versions because they are not in the default api level package.. so use app:showAsAction and add something like this {xmlns:app="http://schemas.android.com/apk/res-auto"} -which i believe you had already done that, restart and rebuild your project – Elltz Oct 16 '14 at 19:50
  • My min SDK is 14. Just rebuilt the project - to no avail. I try and use compileSdk 14 and BuildTools 14.1.0. Does is affect my project? (I thought I should use compileSdk and buildTools as low as possible, so as my min SDK, to be sure I support the older versions. Is that correct?) – 3yakuya Oct 16 '14 at 21:02
  • 1
    I have this problem too. I'm finding dealing with action bars very complicated. My min SDK is 16. Many resources, even official ones, take great pains to make things work using AppCompat and v7 support library etc but I am unable to support such old versions for unrelated reasons. My main problem is that I cannot use an AppCompatActivity because I need to use a ListActivity. I have failed to figure out how to make Android Studio not report an error and I'm in just the same position as the OP: works with android, not with app, so I'm leaving it as android and crossing my fingers. – Yannick Oct 25 '15 at 13:13
  • 1
    In my mind the underlying question here remains unanswered. I still have no idea why showAsAction does not work in the app namespace. I am attempting to put an action bar on a ListActivity. As I've said, my current solution seems to work fine on my min API (4.1) and on target API (current). – Yannick Oct 25 '15 at 13:16

1 Answers1

11

This is the documentation of the lint rule:

AppCompatResource

Summary: Menu namespace

Priority: 5 / 10

Severity: Error

Category: Usability

When using the appcompat library, menu resources should refer to the showAsAction in the app: namespace, not the android: namespace.

Similarly, when not using the appcompat library, you should be using the android:showAsAction attribute.

I think the problem is that you are mixing Framework Activity and AppCompat menu.

You should use AppCompatActivity with AppCompat Action bar and app:showAsAction; or Activity with android:showAsAction.

rds
  • 26,253
  • 19
  • 107
  • 134
  • the problem is that app:showAsAction="ifRoom" and android:showAsAction="ifRoom" should behave the same but they don't. Probably depending if one uses new Toolbar vs ActionBar – Ewoks May 25 '16 at 09:07