android.widget.ToggleButtonを使用します。
ToggleButtonを使ったサンプル
■ソースコード
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toggle);
// トグルボタンのチェックイベントを設定
((ToggleButton)findViewById(R.id.sample_toggle)).setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
if (view.getId() == R.id.sample_toggle) {
Log.d("TAG", "toggle:" + isChecked);
}
}
■レイアウト
<FrameLayout 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:background="#ffffff"
android:padding="0dp" >
<ToggleButton
android:id="@+id/sample_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="トグルボタン"
android:textOff="とぐる おん"
android:textOn="とぐる おふ" >
</ToggleButton>
</FrameLayout>
0 件のコメント:
コメントを投稿