Lập trình Android với ToggleButton ppt

4 176 0
Lập trình Android với ToggleButton ppt

Đang tải... (xem toàn văn)

Thông tin tài liệu

  !" #$%&''(')*+,*-'.%&$  /(" 0123#45364 ' "789: 2;82:  ;8#"<" 9=41 "*> & ; <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Demo ToggleButton" android:id="@+id/tv" /> <ToggleButton android:text="ToggleButton" android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOn="yello" android:textOff="red" /> </LinearLayout> ?@ A!#*B3#3#"C1 android:textOn="yello" android:textOff="red” DE 'F9' G'"H4I 82"5  =J & ; package com.ToggleButton; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; http://www.laptrinhdidong.vn Page 1 4;KKBBB" 4" # import android.widget.ToggleButton; public class ToggleButtonActivity extends Activity implements OnClickListener{ ToggleButton tg; TextView tv; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView) findViewById(R.id.tv); tv.setBackgroundColor(0xfff00000); tg = (ToggleButton) findViewById(R.id.toggleButton1); tg.setOnClickListener(this); } public void onClick(View v) { // TODO Auto-generated method stub if((tg.isChecked())) { System.out.println("checked"); tv.setBackgroundColor(0xffffff00); tv.setText("Checked"); ////Xu ly tiep xu kien } else { System.out.println("Unchecked"); tv.setBackgroundColor(0xfff00000); tv.setText("Not Checked"); ////Xu ly tiep xu kien } } } L&@ A*+,*-'39' MJ *?B"9 7* 'HDN ; OP1; http://www.laptrinhdidong.vn Page 2 4;KKBBB" 4" Q 9'; OG9'; http://www.laptrinhdidong.vn Page 3 4;KKBBB" 4" R 9S M:,'H!!4*T4H  4;KKBBB" 4">7U" http://www.laptrinhdidong.vn Page 4 4;KKBBB" 4" V . < ;ToggleButton android: text=" ;ToggleButton& quot; android: id="@+id /toggleButton1 " android: layout_width="wrap_content" android: layout_height="wrap_content" android: textOn="yello". > <TextView android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="Demo ToggleButton& quot; android: id="@+id/tv" /> < ;ToggleButton. encoding="utf-8"?> <LinearLayout xmlns :android= "http://schemas .android. com/apk/res /android& quot; android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent"

Ngày đăng: 07/08/2014, 07:21

Tài liệu cùng người dùng

Tài liệu liên quan