トグルボタンを表示する |
ここではトグルボタンを表示するためのToggleButtonクラスの使い方を確認していきます。 ToggleActivity.java package goodroid.sample.toggle; import android.app.Activity; import android.os.Bundle; public class ToggleActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> 実行結果 ![]() ![]() 次に、トグルボタンの表示されている「off」と「on」の表示を変えてみましょう。 変え方は簡単で、以下のようにXMLコードを修正します。 main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOff="オフ" android:textOn="オン" /> </LinearLayout> 11行目と12行目のandroid:textOffとandroid:textOnで表示したい文字を設定します。 「android:textOff」に指定した文字列がOFFのときに表示され、「android:textOn」に指定した文字列がONのときに表示されます。サンプルプログラムではトグルボタンの文字列を「オフ」「オン」に変更しています。 実行結果 ![]() ![]() |
3395 views | コメント:0 | 2012-05-20 |
コメント
|
|
まだこの記事にコメントはありません |