6

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Leon
  • 307
  • 3
  • 16
  • https://stackoverflow.com/questions/29732512/difference-between-android-and-app-prefix-in-android-xml – Raghunandan Jun 02 '17 at 05:24
  • 1
    Possible duplicate of [What is the 'app' Android XML namespace?](https://stackoverflow.com/questions/26692233/what-is-the-app-android-xml-namespace) – VishnuSP Jun 02 '17 at 05:25
  • thanks for reply so quickly, I know prefix android and app, but why I get error when using android:actionViewClass, if imported widget.SearchView rather than v7.widget.SearchView? – Leon Jun 02 '17 at 05:28

1 Answers1

8

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?

  • Thanks, what let me confused is, I think android:actionviewclass is fitted for widget. Search view, not for support library class. But why when using widget. Searchview, still can't use android:actionviewclass, see error I have said above. – Leon Jun 03 '17 at 08:17
  • visit this:-https://stackoverflow.com/questions/30451740/android-searchview-in-toolbar-not-expanding – Vishal kumar singhvi Jun 03 '17 at 08:22