I have inside my mainActivty, a menu to which I set a Switch in this way
activity_main_drawer.xml
<item
android:icon="@drawable/ic_light"
app:actionLayout="@layout/menu_switch"
android:title="Modo"
/>
And inside the menu_switch.xml
<Switch xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_switch"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
/>
How could I access the state of the switch (nav_switch) from the activityMain?, to grant actions in case the switch was checked or not. Thank you
To get the status of a Switch use OnCheckedChangeListener , define this listener to your Switch and you will be able to get its status: