Tải bản đầy đủ (.docx) (4 trang)

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

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (88.39 KB, 4 trang )


 !"
#$%&''(')*+,*-'.%&$
 /("
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=" /> 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;

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;

Page 2
4;KKBBB" 4" Q
9';
OG9';

Page 3
4;KKBBB" 4" R
9S M:,'H!!4*T4H 
4;KKBBB" 4">7U"

Page 4
4;KKBBB" 4" V

×