您好,登錄后才能下訂單哦!
這篇文章主要介紹“Android中如何實現鍵盤操作”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“Android中如何實現鍵盤操作”文章能幫助大家解決問題。
一般是如下三個Android鍵盤操作的函數:
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;
}
}
關于“Android中如何實現鍵盤操作”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識,可以關注億速云行業資訊頻道,小編每天都會為大家更新不同的知識點。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。