android开关按钮资源图片,Android——图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟...
packagecom.example.chenshuai.test322;importandroid.content.Intent;importandroid.net.Uri;importandroid.os.Bundle;importandroid.support.v7.app.AppCompatActivity;importandroid.view.View;importandroid.wid
packagecom.example.chenshuai.test322;importandroid.content.Intent;importandroid.net.Uri;importandroid.os.Bundle;importandroid.support.v7.app.AppCompatActivity;importandroid.view.View;importandroid.widget.Button;importandroid.widget.CompoundButton;importandroid.widget.DatePicker;importandroid.widget.ImageView;importandroid.widget.Switch;importandroid.widget.TimePicker;importandroid.widget.Toast;importandroid.widget.ToggleButton;/*** Created by chenshuai anniu1 2016/3/28.*/
public class Longclick extendsAppCompatActivity {
ImageView iv;
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.longclicklayout);//状态开关 开关变 图片变
iv=(ImageView) findViewById(R.id.iv);
ToggleButton tob=(ToggleButton) findViewById(R.id.tob);
tob.setOnCheckedChangeListener(newTocheckedlistene());
//推拉开关
Switch swt=(Switch) findViewById(R.id.swt);
swt.setOnCheckedChangeListener(newTocheckedlistene());
DatePicker datePicker=(DatePicker)findViewById(R.id.dp_1);//日期选择器的监听
datePicker.init(2000, 0, 1, newDatePicker.OnDateChangedListener() {
@Overridepublic void onDateChanged(DatePicker view, int year, int monthOfYear, intdayOfMonth) {
Toast.makeText(Longclick.this, year + "-" + (monthOfYear + 1) + "-" +dayOfMonth, Toast.LENGTH_SHORT).show();
}
});//时间选择器的监听 OnTimeChangedListener()
TimePicker tpk =(TimePicker)findViewById(R.id.tpk);
Toast.makeText(Longclick.this, datePicker.getYear()+ "-" + (datePicker.getMonth()+1) +"-" +datePicker.getDayOfMonth()+ tpk.getHour() + "-" +tpk.getMinute(), Toast.LENGTH_SHORT).show();
tpk.setOnTimeChangedListener(newTimePicker.OnTimeChangedListener() {
@Overridepublic void onTimeChanged(TimePicker view, int hourOfDay, intminute) {
Toast.makeText(Longclick.this, hourOfDay + ":" +minute, Toast.LENGTH_SHORT).show();
}
});private class Tocheckedlistene implementsCompoundButton.OnCheckedChangeListener {
@Overridepublic void onCheckedChanged(CompoundButton buttonView, booleanisChecked) {if(isChecked) {
iv.setImageResource(R.drawable.anniu1);
}else{
iv.setImageResource(R.drawable.anniu2);
}
}
}
}
更多推荐
所有评论(0)