侦听键盘操作

作者:追风剑情 发布于:2015-7-26 17:19 分类:Android

package com.example.androidtest;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class UIActivityActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uiactivity);
	}
	
	/**
	 * @return true:告诉系统您已经处理完此事件并且系统不要再作进一步的处理。
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)
	{
		switch (keyCode)
		{
		case KeyEvent.KEYCODE_DPAD_CENTER:
			Toast.makeText(getBaseContext(), "Center was clicked", Toast.LENGTH_LONG).show();
			break;
		case KeyEvent.KEYCODE_DPAD_LEFT:
			Toast.makeText(getBaseContext(), "Left arrow was clicked", Toast.LENGTH_LONG).show();
			break;
		case KeyEvent.KEYCODE_DPAD_RIGHT:
			Toast.makeText(getBaseContext(), "Right arrow was clicked", Toast.LENGTH_LONG).show();
			break;
		case KeyEvent.KEYCODE_DPAD_UP:
			Toast.makeText(getBaseContext(), "Up arrow was clicked", Toast.LENGTH_LONG).show();
			break;
		case KeyEvent.KEYCODE_DPAD_DOWN:
			Toast.makeText(getBaseContext(), "Down arrow was clicked", Toast.LENGTH_LONG).show();
			break;
		}
		return false;
	}
	
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event)
	{
		switch (keyCode)
		{
		
		}
		return false;
	}
}

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号