伟哥~ YZ

大学剩下的日子 要在公司度过了,马上要步入大四啦!!!写写博客和大家分享编程经验。QQ 812200157。...

Android 按键处理

package rw.key;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.SurfaceView;

public class KetTestActivity extends Activity {
    /** Called when the activity is first created. */
	 Paint paint=new Paint();
     String string="";
	class MySurfaceView extends SurfaceView{
       
		public MySurfaceView(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
			setFocusable(true);//聚焦
			requestFocus();
			paint.setColor(Color.RED);
			paint.setAntiAlias(true);
			paint.setTextSize(30);
		}
		public void OnDraw(){
			Canvas canvas=getHolder().lockCanvas();
			canvas.drawColor(Color.BLUE);
			canvas.drawText(string, 0, paint.getTextSize(), paint);
			getHolder().unlockCanvasAndPost(canvas);
		}
		
		@Override
		public boolean onKeyDown(int keyCode, KeyEvent event) {
			// TODO Auto-generated method stub,当按下一个键
			if (keyCode==KeyEvent.KEYCODE_BACK) {
				return false;
			}
			string="你按下的是"+"key["+keyCode+"]";
			OnDraw();
			return true;
		}
		
		@Override
		public boolean onKeyLongPress(int keyCode, KeyEvent event) {
			// TODO Auto-generated method stub
			
			return super.onKeyLongPress(keyCode, event);
		}
		
		@Override
		public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
			// TODO Auto-generated method stub
			return super.onKeyMultiple(keyCode, repeatCount, event);
		}
		
		@Override
		public boolean onKeyUp(int keyCode, KeyEvent event) {
			// TODO Auto-generated method stub
			return super.onKeyUp(keyCode, event);
		}
	    
	}
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new MySurfaceView(getApplicationContext()));
    }
	
	
}


 

阅读更多
个人分类: Android 小知识
想对作者说点什么? 我来说一句

Android 处理按键的响应方式

2011年09月26日 180KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭