Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app:showAsAction vs android:showAsAction

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?

like image 208
3yakuya Avatar asked Oct 16 '14 19:10

3yakuya


People also ask

What is showAsAction in Android?

android:showAsAction Keyword. When and how this item should appear as an action item in the app bar. A menu item can appear as an action item only when the activity includes an app bar.

How to add action bar in android?

To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.

What is action in android studio?

In Google's definition, an Action is: “An interaction you build for the Assistant that supports a specific intent and has a corresponding fulfillment that processes the intent”.


1 Answers

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.

like image 93
rds Avatar answered Nov 16 '22 02:11

rds