<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/show_toast" android:onClick="showToast"> </Button>
/**
* @description 显示toast提示信息
* @author zhuyangxing 2013-11-22上午9:26:00
* @param v
*/
public void showToast(View v){
Toast.makeText(MainActivity.this, "这里是提示信息", Toast.LENGTH_SHORT).show();
}
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/changeToRed" android:id="@+id/button2"> </Button>
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button2 = (Button) findViewById(R.id.button2);//获得句柄
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
text.setBackgroundColor(Color.RED);
}
});
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testevent);
mText = (TextView) findViewById(R.id.text1);
mButton1 = (Button) findViewById(R.id.button1);
mButton1.setOnClickListener(this); // 设置监听的类
mButton2 = (Button) findViewById(R.id.button2);
mButton2.setOnClickListener(this); // 设置监听的类
}
public void onClick(View v) {
Log.v(TAG, "onClick()");
switch(v.getId()){ // 区分不同的控件
case R.id.button1:
mText.setBackgroundColor(Color.RED);
break;
case R.id.button2:
mText.setBackgroundColor(Color.GREEN);
break;
default:
Log.v(TAG, "other");
break;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有