2011-11-07 114 views
3

我想用键盘上方的Prev,Next按钮显示虚拟键盘。需要键盘上方的上一个按钮和下一个按钮

当用户点击上一个按钮时,光标应该移到上一个编辑文本输入字段,点击下一个按钮应该进入视图中下一个编辑文本字段。

我想在我自己的活动中使用这些按钮。我怎样才能做到这一点?

+0

可以覆盖的onkeydown()方法。 –

回答

2

这可以通过将android:windowSoftInputMode =“adjustPan”添加到清单中的活动 元素来实现。例如。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.codename.android" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" 
     android:label="@string/app_name" 
     android:theme="@style/MyTheme" 
     > 

     <activity android:name=".MainActivity" 
        android:label="@string/app_name" 
        android:windowSoftInputMode="adjustPan"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 
    <uses-sdk android:minSdkVersion="7" /> 
</manifest> 

这可以防止在显示虚拟键盘时调整视图的大小。

+0

如果我想显示下一步,并完成按钮命中该键盘..当我点击编辑文本键盘打开并包括下一个按钮在下一个editext框中移动。并完成键完成键入..我怎样才能做到这一点.. – eagle

+0

添加意图onClickListener的“下一步”按钮移动到下一个编辑文本框。并使用android:editable =“false”完成按钮来锁定键入。 – himanshu

2

您可以在布局中为Edittext设置适当的IME选项。

android:imeOptions="actionNext" 

并做

机器人:imeOptions = “actionDone”

1
Android code to override the "Done" button in my EditText field: 

myEditField.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      if (actionId == EditorInfo.IME_ACTION_DONE) { 

       InputMethodManager imm =(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); 
       imm.hideSoftInputFromWindow(getWindowToken(), 0);//hide the keyboard. 

       return true; 
      } 
      return false; 
     } 
    }); 
相关问题