I created a small test app to practice setting up the action bar in a normal Activity (not ActionBarActivity), since I'm only planning on working with API level 15 and above. I want to display the search icon on the Action Bar. If I set up the menu_main.xml file like this, I can display the search icon, but not without an error:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
android:showAsAction="ifRoom"/>
</menu>
I can get the app to run just fine in my emulator and show the icon, but an error pops while in Android Studio:
"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 can make the error go away by deleting the following line from the build.gradle file:
compile 'com.android.support:appcompat-v7:22.0.0'
However, it doesn't seem like a good idea to remove the support library (although I could be wrong here). If I use the app:namespace method like the error recommends, I can get rid of the error, but then the search icon does not show up on the action bar; instead, the search option appears in the overflow menu. How can I properly display the search icon without getting an error and without removing the support library? Do I just ignore the error? Should I just stick with using an ActionBarActivity for my apps (i.e., is there a reason to try to use a normal Activity with an Action Bar or am I wasting my time)? I'm using Android Studio for this project.