80,351
社区成员
发帖
与我相关
我的任务
分享
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onefindView();
twofindView();
MyOnTouchListener[] touch = new MyOnTouchListener[7];
MyButton listener = new MyButton();
for(int i=0;i<=6;i++){
oneyuansu[i].setOnClickListener(listener);
}
for(int i=0;i<=5;i++){
twoyuansu[i].setOnClickListener(listener);
}
}
class MyButton implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,Information.class);
System.out.println("jbkjblkhkj");
startActivity(intent);
}
}
package redknot.example.elements;
import android.app.Activity;
import android.content.Intent;
import android.graphics.ColorMatrixColorFilter;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.ImageButton;
public class MainActivity extends Activity {
private ImageButton[] oneyuansu = new ImageButton[7];
private ImageButton[] twoyuansu = new ImageButton[6];
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onefindView();
twofindView();
MyOnTouchListener touch = new MyOnTouchListener();
for(int i=0;i<=6;i++){
oneyuansu[i].setOnClickListener(new MyButton(i));
}
for(int i=0;i<=5;i++){
twoyuansu[i].setOnClickListener(new MyButton(i));
}
}
class MyButton implements OnClickListener{
private int c;
public MyButton(int i){
c = i;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println(c);
Intent intent = new Intent(MainActivity.this,Information.class);
startActivity(intent);
}
}
public void onefindView(){
oneyuansu[0] = (ImageButton) findViewById(R.id.h1);
oneyuansu[1] = (ImageButton) findViewById(R.id.li1);
oneyuansu[2] = (ImageButton) findViewById(R.id.na1);
oneyuansu[3] = (ImageButton) findViewById(R.id.k1);
oneyuansu[4] = (ImageButton) findViewById(R.id.rb1);
oneyuansu[5] = (ImageButton) findViewById(R.id.cs1);
oneyuansu[6] = (ImageButton) findViewById(R.id.fr1);
}
public void twofindView(){
twoyuansu[0] = (ImageButton) findViewById(R.id.be1);
twoyuansu[1] = (ImageButton) findViewById(R.id.mg1);
twoyuansu[2] = (ImageButton) findViewById(R.id.ca1);
twoyuansu[3] = (ImageButton) findViewById(R.id.sr1);
twoyuansu[4] = (ImageButton) findViewById(R.id.ba1);
twoyuansu[5] = (ImageButton) findViewById(R.id.ra1);
}
/*为了使图片按钮按下和弹起状态不同,采用过滤颜色的方法.按下的时候让图片颜色变淡*/
public class MyOnTouchListener implements OnTouchListener{
public final float[] BT_SELECTED=new float[]
{ 2, 0, 0, 0, 2,
0, 2, 0, 0, 2,
0, 0, 2, 0, 2,
0, 0, 0, 1, 0 };
public final float[] BT_NOT_SELECTED=new float[]
{ 1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0 };
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_DOWN){
System.out.println("ijksahfkjshqklf");
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
else if(event.getAction() == MotionEvent.ACTION_UP){
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
return false;
}
}
}