android - Enable and Disable MenuItem on Navigation Drawer Activity Layout
<p>I have and app created using the Navigation Drawer <code>Activity</code> Layout.. And I need to <strong>enable/disable</strong> some items programmatically</p>

<p><a href="http://i.stack.imgur.com/oO2BF.jpg" rel="noreferrer">Menu Example</a></p>

<p>Example: I want to disable the Menu Item id nav_item2</p>

<p>I tried to do...</p>

<pre><code>MenuItem nav_item2 = (MenuItem)findViewById(R.id.nav_item2);
nav_item2.setEnabled(false);
</code></pre>

<p>And it return a <strong>NullPointerException</strong> to me..</p>

<p>Also tried...</p>

<pre><code>@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    nav_item2 = menu.findItem(R.id.nav_item2);
    return true;
}
</code></pre>

<p>with the same <strong>NullPointerException</strong></p>

<p>Someone know something to do?</p>

<p>nav_header_main_activity.xml (Generated with the Layout Creation)</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"&gt;

    &lt;ImageView
        android:id="@+id/imageView"
        android:layout_width="199dp"
        android:layout_height="72dp"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:src="@drawable/ciag" /&gt;

    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:text="CIAg"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1" /&gt;

    &lt;TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="dev@ciag.org.br" /&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>main_activity_navigation_drawer.xml (generated on the layout creation)</p>

<p>
</p>

<pre><code>&lt;group android:checkableBehavior="single"&gt;
    &lt;item
        android:id="@+id/nav_save"
        android:icon="@android:drawable/ic_menu_save"
        android:enabled="false"
        android:title="@string/nav_save" /&gt;
    &lt;item
        android:id="@+id/nav_graph"
        android:icon="@drawable/chart_bar"
        android:enabled="false"
        android:title="@string/nav_graph" /&gt;
    &lt;item
        android:id="@+id/nav_send"
        android:icon="@drawable/ic_menu_send"
        android:title="Enviar" /&gt;
&lt;/group&gt;

&lt;item android:title="Configurações"&gt;
    &lt;menu&gt;
        &lt;item
            android:id="@+id/nav_manage"
            android:icon="@drawable/ic_menu_manage"
            android:enabled="false"
            android:title="@string/nav_manage" /&gt;
        &lt;item
            android:id="@+id/nav_support"
            android:icon="@android:drawable/ic_menu_help"
            android:title="@string/nav_support" /&gt;
    &lt;/menu&gt;
&lt;/item&gt;
</code></pre>

<p></p>