您好,登錄后才能下訂單哦!
這篇文章主要介紹“Android中如何實現(xiàn)鍵盤操作”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Android中如何實現(xiàn)鍵盤操作”文章能幫助大家解決問題。
一般是如下三個Android鍵盤操作的函數(shù):
onKeyDown, onKeyUp, on, onKeyMultiple
參看如下Android鍵盤操作代碼:
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class TestProgress extends Activity {
private ProgressDialog progress = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, Menu.FIRST+1, 1, "Open Progress");
menu.add(0, Menu.FIRST+2, 2, "Exit");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId())
{
case Menu.FIRST +1:
{
progress = new ProgressDialog(this);
progress.setTitle("Progress!!");
progress.setMessage("Please wait for the operation...");
progress.setCancelable(true);
progress.show();
//progress = ProgressDialog.show(this, "Progress!",
"Please wait for operation...");break;
}
case Menu.FIRST +2:
{
finish();
break;
}
}
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
super.onKeyDown(keyCode, event);
setTitle("you pressed key:" + String.valueOf(keyCode));
return true;
}
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount,
KeyEvent event) {// TODO Auto-generated method stub
super.onKeyMultiple(keyCode, repeatCount, event);
TextView tv = (TextView)this.findViewById(R.id.mainview);
tv.setText("you have press key:[" + String.valueOf(keyCode) + "]
for:" + String.valueOf(repeatCount) + "Times!");return true;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
super.onKeyUp(keyCode, event);
setTitle("you release key:" + String.valueOf(keyCode));
return true;
}
}
關(guān)于“Android中如何實現(xiàn)鍵盤操作”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。