.Net学习爱好者的温馨家园

.Net互动平台

导航

1:设置软键盘

如图所示我们可以修改软键盘的Enter按钮的样式,可以在代码中监听 按钮点击事件。

 

 

1.package cn.m15.xys; 
2. 
3.import Android.app.Activity;  4.import Android.os.Bundle;  5.import Android.view.KeyEvent;  6.import Android.view.inputmethod.EditorInfo;  7.import Android.widget.EditText;  8.import Android.widget.TextView;  9.import Android.widget.Toast;  10.import Android.widget.TextView.OnEditorActionListener;  11. 
12.public class KeyBoardActivity extends Activity {  13.    @Override  14.    protected void onCreate(Bundle savedInstanceState) {  15.    setContentView(R.layout.keyboard); 
16. 
17.    EditText editText0 = (EditText)findViewById(R.id.txtTest0); 
18.     
19.    editText0.setOnEditorActionListener(new OnEditorActionListener() {  20. 
21.        @Override  22.        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {  23.        if (arg1 == EditorInfo.IME_ACTION_GO) {  24.            Toast.makeText(KeyBoardActivity.this, "你点了软键盘'去往'按钮",  25.                Toast.LENGTH_SHORT).show(); 
26.        } 
27.        return false;  28.        } 
29.    }); 
30.    EditText editText1 = (EditText)findViewById(R.id.txtTest1); 
31.     
32.    editText1.setOnEditorActionListener(new OnEditorActionListener() {  33. 
34.        @Override  35.        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {  36.        if (arg1 == EditorInfo.IME_ACTION_SEARCH) {  37.            Toast.makeText(KeyBoardActivity.this, "你点了软键盘'搜索'按钮",  38.                Toast.LENGTH_SHORT).show(); 
39.        } 
40.        return false;  41.        } 
42.    }); 
43.    EditText editText2 = (EditText)findViewById(R.id.txtTest2); 
44.     
45.    editText2.setOnEditorActionListener(new OnEditorActionListener() {  46. 
47.        @Override  48.        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {  49.        if (arg1 == EditorInfo.IME_ACTION_SEND) {  50.            Toast.makeText(KeyBoardActivity.this, "你点了软键盘'发送'按钮",  51.                Toast.LENGTH_SHORT).show(); 
52.        } 
53.        return false;  54.        } 
55.    }); 
56.    EditText editText3 = (EditText)findViewById(R.id.txtTest3); 
57.     
58.    editText3.setOnEditorActionListener(new OnEditorActionListener() {  59. 
60.        @Override  61.        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {  62.        if (arg1 == EditorInfo.IME_ACTION_NEXT) {  63.            Toast.makeText(KeyBoardActivity.this, "你点了软键盘'下一个'按钮",  64.                Toast.LENGTH_SHORT).show(); 
65.        } 
66.        return false;  67.        } 
68.    }); 
69.    EditText editText4 = (EditText)findViewById(R.id.txtTest4); 
70.     
71.    editText4.setOnEditorActionListener(new OnEditorActionListener() {  72. 
73.        @Override  74.        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {  75.        if (arg1 == EditorInfo.IME_ACTION_DONE) {  76.            Toast.makeText(KeyBoardActivity.this, "你点了软键盘'完成'按钮",  77.                Toast.LENGTH_SHORT).show(); 
78.        } 
79.        return false;  80.        } 
81.    }); 
82.    EditText editText5 = (EditText)findViewById(R.id.txtTest5); 
83.     
84.    editText5.setOnEditorActionListener(new OnEditorActionListener() {  85. 
86.        @Override  87.        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {  88.        if (arg1 == EditorInfo.IME_ACTION_UNSPECIFIED) {  89.            Toast.makeText(KeyBoardActivity.this, "你点了软键盘'未指定'按钮",  90.                Toast.LENGTH_SHORT).show(); 
91.        } 
92.        return false;  93.        } 
94.    }); 
95.    super.onCreate(savedInstanceState);  96.    } 
97.} 

 

布局:

 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android
    Android:id="@+id/textviewll" 
    Android:orientation="vertical" android:layout_width="fill_parent" 
   Android:layout_height="fill_parent"> 
   <EditText Android:id="@+id/txtTest0"  
    Android:imeOptions="actionGo" 
     Android:layout_width="fill_parent" 
    Android:layout_height="wrap_content" 
     Android:hint="特殊按钮-去往"></EditText> 
   <EditText Android:id="@+id/txtTest1"  
     Android:imeOptions="actionSearch" 
     Android:layout_width="fill_parent" 
    Android:layout_height="wrap_content" 
     Android:hint="特殊按钮-搜索"></EditText> 
   <EditText Android:id="@+id/txtTest2"  
     Android:imeOptions="actionSend" 
     Android:layout_width="fill_parent" 
     Android:layout_height="wrap_content" 
     Android:hint="特殊按钮-发送"></EditText> 
    <EditText Android:id="@+id/txtTest3"  
     Android:imeOptions="actionNext" 
     Android:layout_width="fill_parent" 
     Android:layout_height="wrap_content" 
    Android:hint="特殊按钮-下一个"></EditText> 
    <EditText Android:id="@+id/txtTest4"  
     Android:imeOptions="actionDone" 
     Android:layout_width="fill_parent" 
     Android:layout_height="wrap_content" 
     Android:hint="特殊按钮-完成"></EditText> 
    <EditText Android:id="@+id/txtTest5"  
     Android:imeOptions="actionUnspecified" 
     Android:layout_width="fill_parent" 
     Android:layout_height="wrap_content" 
     Android:hint="特殊按钮-未指定"></EditText> 
</LinearLayout>

posted on 2011-11-29 17:01  Xt Idt  阅读(750)  评论(0编辑  收藏  举报