5

我有一个 android xml 布局,当用户按下键盘上的下一步时,我想指定字段的焦点顺序。

文档说,android:nextFocusForward=TARGET_ID应该做到这一点。但它在我们所有的测试设备上都被忽略了。一些运行 2.3 的旧设备和运行 4.1 的新 Nexus 设备。

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:textCursorDrawable="@null"
            android:id="@+id/firstname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="6dp"
            android:layout_marginTop="6dp"
            android:layout_weight="1"
            android:singleLine="true"
            android:background="#00000000"
            android:textColor="#000"
            android:nextFocusForward="@+id/lastname"
            android:padding="2dp"/>

        <EditText
            android:textCursorDrawable="@null"
            android:id="@+id/lastname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="6dp"
            android:layout_marginTop="6dp"
            android:layout_weight="1"
            android:background="#00000000"
            android:singleLine="true"
            android:textColor="#000"
            android:padding="2dp"/>
    </LinearLayout>

我在这里做错了什么???就是想不通。非常感谢!

4

4 回答 4

11

也试试 nextFocusDown。我不完全理解规则,但似乎行为取决于 EditTexts 的布局,以及光标位置相对于下一个字段的位置。

于 2013-02-21T22:01:46.123 回答
0

我尝试设置 nextFocusDown、nextFocusForward、nextFocusRight,但它们都不起作用。我通过侦听编辑器操作并以编程方式将焦点设置到下一个 EditText 来使其工作。

    mFirstName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            mLastName.requestFocus();
            return true;
        }
    });
于 2017-01-05T15:53:18.603 回答
0

我在 JetPack 的工具栏/操作栏中遇到了类似的问题。我似乎工具栏小部件完全忽略了 nextFocus 属性。我通过不使用那些遗留小部件并使用基于标准小部件的自定义工具栏来解决它。

于 2020-05-01T04:03:14.297 回答
0

已经很久了,但我刚刚遇到问题并找到了解决方案。当 AutoCompleteTextView 被 imeOptions 覆盖时,nextFocusForward 起作用。我的 EditText 字段中有这段代码,它可以工作:

android:imeOptions="actionNext"
android:nextFocusForward="@+id/et_xyz"
于 2021-07-21T15:55:49.120 回答