Add Switch widget to ActionBar and respond to change event
问题 Can I know how to add Switch widget in ActionBar and handle the click event or toggle change event. For now I can inflate the Switch in ActionBar but unable to respond to change event. I have added below to main.xml. <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.MainActivity" > <item android:id="@+id/toggleservice" android:actionViewClass="android.widget.Switch" android:showAsAction="ifRoom" android