I want my refresh item to appear on the top bar. I am extending ListActivity
and using the theme android:Theme.Holo.Light.DarkActionBar
. The menu is created using:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="eu.pcas_project.client.android.pa.services.ServiceList">
<item
android:id="@+id/refresh_all_services"
android:title="@string/refresh_all_services"
android:icon="@drawable/ic_menu_refresh"
app:showAsAction="always" />
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_service_list, menu);
return super.onCreateOptionsMenu(menu);
}
If I change app:showAsAction="always"
on the menu XML to android:showAsAction="always"
, this works as I want it to—icon on top bar—but then I get an error saying Should use android:showAsAction when not using the appcompat library. Can it be fixed?
Targeting API 19.
As said in the question, android:showAsAction="always"
works but generates an error.
While the project was not using the appcompat library directly, I discovered that a library imported by said project had com.android.support:appcompat-v7:XXX.YYY.ZZZ
as a dependency even though it was not needed. This was added by Android Studio. Once the line was removed and the project rebuilt the error disappeared and the refresh icon appeared on the top right corner instead of on the menu.