Move to another EditText when Soft Keyboard Next is clicked on Android(在 Android 上单击软键盘 Next 时移动到另一个 EditText)
问题描述
当我按下下一步"时,用户 EditText 上的焦点必须移至密码.然后,从密码,它必须向右移动,依此类推.你能帮我写代码吗?
When I press the 'Next', the focus on the User EditText must be move to the Password. Then, from Password, it must move to the right and so on. Can you help me on how to code it?
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name*" />
<EditText
android:id="@+id/txt_User"
android:layout_width="290dp"
android:layout_height="33dp"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password*" />
<EditText
android:id="@+id/txt_Password"
android:layout_width="290dp"
android:layout_height="33dp"
android:singleLine="true"
android:password="true" />
<TextView
android:id="@+id/confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password*" />
<EditText
android:id="@+id/txt_Confirm"
android:layout_width="290dp"
android:layout_height="33dp"
android:singleLine="true"
android:password="true" />
</LinearLayout>
推荐答案
焦点处理
焦点移动基于找到最近的算法给定方向的邻居.在极少数情况下,默认算法可能与开发人员的预期行为不匹配.
Focus Handling
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer.
使用以下 XML 属性更改定向导航的默认行为:
Change default behaviour of directional navigation by using following XML attributes:
android:nextFocusDown="@+id/.."
android:nextFocusLeft="@+id/.."
android:nextFocusRight="@+id/.."
android:nextFocusUp="@+id/.."
除了定向导航,您还可以使用标签导航.为此,您需要使用
Besides directional navigation you can use tab navigation. For this you need to use
android:nextFocusForward="@+id/.."
要获得特定视图的焦点,请调用
To get a particular view to take focus, call
view.requestFocus()
要监听某些变化的焦点事件,请使用 View.OnFocusChangeListener
To listen to certain changing focus events use a View.OnFocusChangeListener
您可以使用 android:imeOptions
用于处理键盘上的额外按钮.
You can use android:imeOptions
for handling that extra button on your keyboard.
您可以在与编辑器关联的 IME 中启用的其他功能改进与您的应用程序的集成.这里的常数对应于 imeOptions 定义的那些.
Additional features you can enable in an IME associated with an editor to improve the integration with your application. The constants here correspond to those defined by imeOptions.
imeOptions 的常量包括各种动作和标志,请参阅上面的链接了解它们的值.
The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
值示例
ActionNext:
操作键执行下一步"操作,将用户带到下一个接受文本的字段.
the action key performs a "next" operation, taking the user to the next field that will accept text.
ActionDone:
操作键执行完成"操作,通常意味着无需输入任何内容,IME 将关闭.
the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
代码示例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:imeOptions="actionNext"
android:maxLines="1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="24dp"
android:imeOptions="actionDone"
android:maxLines="1"
android:ems="10" />
</RelativeLayout>
如果您想收听 imeoptions 事件,请使用 TextView.OnEditorActionListener
.
If you want to listen to imeoptions events use a TextView.OnEditorActionListener
.
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
这篇关于在 Android 上单击软键盘 Next 时移动到另一个 EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 上单击软键盘 Next 时移动到另一个 Edi
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01