안 드 로 이 드 개발 ToggleButton 개발 사용 방법
1653 단어 androidToggleButton
XML 코드:
<ToggleButton android:id="@+id/tb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn=" "
android:textOff=" "
android:checked="true"
/> texton 단추 가 열 렸 을 때 표시 되 는 텍스트
textOff 단추 가 닫 혔 을 때 표시 되 는 텍스트
checked 불 러 올 때의 상태, 기본 값 은 false, 즉 닫 기
JAVA 코드
import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ToggleButton tb=(ToggleButton)findViewById(R.id.tb);
tb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
// isChecked
if(isChecked){
Toast.makeText(Main.this," ",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(Main.this," ",Toast.LENGTH_LONG).show();
}
}
});
}
}