If you are using the native action bar, you use android:showAsAction
. Any time you see android:
as a prefix, you know that it is an attribute defined by the Android framework.
If you are using the appcompat-v7
backport of the action bar, that comes from a library (appcompat-v7
). Libraries cannot invent new android:
attributes. Instead, for library-defined attributes, you use a new namespace (e.g., app:
) tied to a http://schemas.android.com/apk/res-auto
URL.
it says that android: namespace is not able to provide access to the property if the we pretend to support older android versions such as 2.1
Correct. In this case, while android:showAsAction
was added to the framework in Android 3.0, part of the goal of appcompat-v7
is to support back to Android 2.1. While Google has a time machine, they have not been using it to "retcon" Android and add in attributes that formerly did not exist.
(though, if they did, we wouldn't know about it, as our past would have been altered to have those attributes, unless we somehow have an existence outside the normal space-time continuum, which frequently seems to involve wearing a cape)
So, appcompat-v7
can use attributes like android:icon
, which existed from Android 1.0, but cannot support an android:showAsAction
prior to Android 3.0. Hence, they have their own attribute.