当我preSS下一步,将重点放在用户的EditText必须移动到密码。然后,从密码,它必须移动到右侧等。你能帮助我如何code呢?
<的LinearLayout
机器人:ID =@ + ID / LinearLayout01
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向>
<的TextView
机器人:ID =@ + ID /用户名
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=用户名*/>
<的EditText
机器人:ID =@ + ID / txt_User
机器人:layout_width =290dp
机器人:layout_height =33dp
机器人:单线=真/>
< / LinearLayout中>
<的LinearLayout
机器人:ID =@ + ID / LinearLayout02
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向>
<的TextView
机器人:ID =@ + ID /密码
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=密码*/>
<的EditText
机器人:ID =@ + ID / txt_Password
机器人:layout_width =290dp
机器人:layout_height =33dp
机器人:单线=真
机器人:密码=真/>
<的TextView
机器人:ID =@ + ID /确认
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=密码*/>
<的EditText
机器人:ID =@ + ID / txt_Confirm
机器人:layout_width =290dp
机器人:layout_height =33dp
机器人:单线=真
机器人:密码=真/>
< / LinearLayout中>
解决方案
聚焦运动是基于一种算法寻找最近 邻居在给定方向。在极少数情况下,默认的算法可能不符合开发商的预期行为。
定向导航使用下面的XML更改默认行为属性:
安卓nextFocusDown =@ + ID / .. 机器人:nextFocusLeft =@ + ID / .. 机器人:nextFocusRight =@ + ID / .. 机器人:nextFocusUp =@ + ID / ..
除了定向导航,你可以使用标签导航。为此,您需要使用
安卓nextFocusForward =@ + ID /.."
要得到一个特定的视图采取集中,调用
view.requestFocus()
要听某些变化的焦点事件使用View.OnFocusChangeListener
您可以使用android:imeOptions处理键盘上额外的按钮。
附加功能,你可以用编辑器相关联的IME启用 改善与您的应用程序的集成。这里的常数 对应于由imeOptions限定。
imeOptions的常量包括各种动作和标记,请参见上述的值的链接。
值例子
ActionNext
操作键执行一个下一个操作,以用户对 下一场将接受文本。
ActionDone
操作键执行完成的操作,通常意味着有什么更多的输入,输入法将被关闭。
code例如:
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<的EditText
机器人:ID =@ + ID / editText1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
机器人:layout_marginLeft =32dp
机器人:layout_marginTop =16DP
机器人:imeOptions =actionNext
机器人:单线=真
机器人:EMS =10>
<不是requestFocus />
< /的EditText>
<的EditText
机器人:ID =@ + ID / editText2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignLeft =@ + ID / editText1
机器人:layout_below =@ + ID / editText1
机器人:layout_marginTop =24dp
机器人:imeOptions =actionDone
机器人:单线=真
机器人:EMS =10/>
< / RelativeLayout的>
如果你想听听imeoptions事件使用TextView.OnEditorActionListener.
editText.setOnEditorActionListener(新TextView.OnEditorActionListener(){
@覆盖
公共布尔onEditorAction(TextView的V,INT actionId,KeyEvent的事件){
如果(actionId == EditorInfo.IME_ACTION_SEARCH){
performSearch();
返回true;
}
返回false;
}
});
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 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.
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()
To listen to certain changing focus events use a View.OnFocusChangeListener
You can use android:imeOptions
for handling that extra button on your keyboard.
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.
The constants of imeOptions includes a variety of actions and flags, see the link above for their values.
Value example
ActionNext :
the action key performs a "next" operation, taking the user to the next field that will accept text.
ActionDone
the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
Code example:
<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:singleLine="true"
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:singleLine="true"
android:ems="10" />
</RelativeLayout>
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;
}
});