是这样的:
因为要在Action Bar 上弄个 Switch 按钮,所以我照
http://stackoverflow.com/questions/12107031/how-to-add-a-switch-to-and...
的方法做了个.
现在做到按钮了,但却不能使用onCheckedChanged来验测按钮的开启
我该怎样做?
这是我实现Action Bar 上 放Switch 的代码
mainmenu.xml
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
android:id="@+id/myswitch"
android:title=""
app:showAsAction="always"
app:actionLayout="@layout/menurelaty"
/>
menurelaty.xml
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/switchForActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_centerVertical="true"
android:checked="false"
/>
我在想:会不会是因为MainActivity上的setContentView是main_activity.xml而不是实现Switch的menurelaty.xml才不能以findViewByid然后.onCheckedChanged 来验测按钮的开启