本文共 991 字,大约阅读时间需要 3 分钟。
方法一、在drawable下新建一个xml 名字"test"
代码如下:然后在 按钮的布局文件中 用 android:background="@drawable/test" 来引用
方法二、调用 setOnTouchListener方法
在布局中定义一个按钮 假设它的地址为 bt_0.java文件中添加 如下代码
引用的 color.bule color.white 为自己定义的颜色资源bt_0 = (Button) findViewById(R.id.btn_0);bt_0.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: bt_0.setBackgroundColor(getResources().getColor(R.color.blue)); break; case MotionEvent.ACTION_UP: bt_0.setBackgroundColor(getResources().getColor(R.color.white)); break; } return true; } });
转载地址:http://kplqf.baihongyu.com/