getActionView() of my MenuItem return null in AppCompat

I had this menu xml that works fine:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      >

    <item
        android:id="@+id/context_menu_save"
        android:actionViewClass="my.app.TextViewPlus"
        android:showAsAction="always"
        android:title="@string/logout"
        android:visible="false"/>
</menu>

But when i started using AppComap v7 i hade null exception when using getActionView().

I change my menu layout to:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:myapp="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/context_menu_save"
        myapp:actionViewClass="my.app.TextViewPlus"
        myapp:showAsAction="always"
        android:title="@string/logout"
        android:visible="false"/>
</menu>

And now it works fine. Can anyone explain, why is it happens?

Upvotes: 1

Views: 2288

Answers (2)

bmul
bmul

Reputation: 390

In Android Studio v1.5, I see the following message for this scenario:

When using the appcompat library, menu resources should refer to the app: namespace, not the android: namespace.

When not using the appcompat library, you should be using the android: namespace.

Upvotes: 2

M S Gadag
M S Gadag

Reputation: 2057

xmlns:myapp this is used when you create your own (or use others) customized views.

xmlns:android this is used when default android views.

so as ur question, i hope ur using your own (or use others) customized views. so u got error.

Upvotes: 2

Related Questions