How to access views insde the actionLayout in menu

<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <group
        android:visible="true"
        android:id="@+id/menu">
        <item
            android:id="@+id/nav_dashboard"
            android:icon="@drawable/ic_dashboard_home"
            android:title="Dashboard" />
        <item
            android:id="@+id/nav_time_sheet"
            android:icon="@drawable/ic_time_sheet"
            android:title="Time Sheet" />
        <item
            android:id="@+id/nav_setting"
            android:icon="@drawable/ic_settings"
            android:title="Setting" />

        <item
            android:id="@+id/nav_messaging"
            android:icon="@drawable/ic_chat"
            android:title="Chat" />

        <item
            android:id="@+id/nav_syn"
            android:icon="@drawable/ic_syncronize"
            android:title="Syncronize"/>

        <item
            android:id="@+id/nav_switcher"
            android:icon="@drawable/ic_mode"
            android:title="Offline Mode"
            android:clickable="false"
            app:actionLayout="@layout/layout_switcher_button" />
    </group>
</menu>


NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
MenuItem itemMenus = navigationView.getMenu().findItem(R.id.nav_switcher);
LinearLayout tracks = (LinearLayout) itemMenus.getActionView();
Switch switcher_mode = (Switch) tracks.findViewById(R.id.nav_drawer_switch);
switcher_mode.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.d("Hello","Hi");
    }
});
Advertisements
This entry was posted in Android Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s