ToggleButton用于切换程序中的某种状态。
ToggleButton有三个XML属性:android:checked,设置该按钮是否被选中,对应的方法为setChecked(boolean);
android:textOff,设置当按钮没有被选中时显示的文本;
android:textOn,设置当按钮没有被选中时显示的文本。
下面的例子示范动态控制布局的例子,随着按钮状态的改变,界面布局在水平和垂直布局之间切换。
XML源代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ToggleButton" >
<ToggleButton
android:id="@+id/togglebutton"