See below menu xml file,
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Search"
android:id="@+id/search_menu"
android:icon="@android:drawable/ic_menu_search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always"/>
That let me confused, if using android:actionViewClass, I will get error like searchview is null, but using app:actionViewClass, everything seems fine. So I am wondering why and differences between android:actionViewClass and app:actionViewClass.
android is usually used for attribute coming from Android SDK itself. app is often used if you are using the support library. You may also see other namespaces if you are using custom views (of your own or form a library).
An action view is an action that provides rich functionality within the app bar. For example, a search action view allows the user to type their search text in the app bar, without having to change activities or fragments. An action provider is an action with its own customized layout.
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. Valid values: Value.
android is usually used for attribute coming from Android SDK itself.
app is often used if you are using the support library.
You may also see other namespaces if you are using custom views (of your own or form a library). ref:-Difference between android: and app: prefix in Android XML?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With