Android 将 EditText imeOptions 设置为 actionNext 没有效果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23036890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting EditText imeOptions to actionNext has no effect
提问by Katedral Pillon
I have a fairly complex (not really) xml layout file. One of the views is a LinearLayout (v1
) with two children: an EditText(v2
) and another LinearLayout(v3
). The child LinearLayout in turn has an EditText(v4
) and an ImageView(v5
).
我有一个相当复杂(不是真的)xml 布局文件。其中一个视图是v1
带有两个子项的 LinearLayout ( ):一个 EditText( v2
) 和另一个 LinearLayout( v3
)。子 LinearLayout 依次具有 EditText( v4
) 和 ImageView( v5
)。
For EditText v2 I have imeOptions as
对于 EditText v2 我有 imeOptions 作为
android:imeOptions="actionNext"
But when I run the app, the keyboard's return
does not check to next
and I want it to change to next
. How do I fix this problem?
但是当我运行该应用程序时,键盘return
不会检查到next
,我希望它更改为next
. 我该如何解决这个问题?
Also, when user clicks next, I want focus to go to EditText v4. I do I do this?
此外,当用户单击下一步时,我希望焦点转到 EditText v4。我这样做吗?
For those who really need to see some code:
对于那些真正需要查看一些代码的人:
<LinearLayout
android:id="@+id/do_txt_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/col6"
android:orientation="vertical"
android:visibility="gone" >
<EditText
android:id="@+id/gm_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/coldo_text"
android:hint="@string/enter_title"
android:maxLines="1"
android:imeOptions="actionNext"
android:padding="5dp"
android:textColor="pigc7"
android:textSize="ads2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal" >
<EditText
android:id="@+id/rev_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/coldo_text"
android:hint="@string/enter_msg"
android:maxLines="2"
android:padding="5dp"
android:textColor="pigc7"
android:textSize="ads2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@drawable/colbtn_r”
android:clickable="true"
android:onClick=“clickAct”
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@drawable/abcat” />
</LinearLayout>
</LinearLayout>
回答by Surendra Kumar
Just add android:maxLines="1" & android:inputType="text"
to your EditText. It will work!! :)
只需添加android:maxLines="1" & android:inputType="text"
到您的 EditText。它会起作用!!:)
回答by pratnala
singleLine
is deprecated. Adding an input type (eg: android:inputType="text"
) also worked for me.
singleLine
已弃用。添加输入类型(例如:)android:inputType="text"
也对我有用。
Use android:maxLines="1"
as singleLine
is deprecated
使用android:maxLines="1"
如singleLine
已被弃用
回答by voghDev
android:singleLine
has been deprecated, it is better to combine android:maxLines="1"
with android:inputType="text"
. This would be the code:
android:singleLine
已弃用,最好android:maxLines="1"
与android:inputType="text"
. 这将是代码:
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
/>
回答by welshk91
The answers given here were all very helpful, but I was still struggling to get my keyboard's "Next" to show.
这里给出的答案都非常有帮助,但我仍在努力让我的键盘的“下一个”显示出来。
Turns out that when you use Android's android:digits
attribute in your XML, it prevents the android:imeOptions="actionNext"
from working as expected.
事实证明,当您android:digits
在 XML 中使用 Android 的属性时,它会阻止android:imeOptions="actionNext"
按预期工作。
The answer is actually to use the deprecated android:singleLine="True"
. This seems to force the IME Option to be respected.
答案实际上是使用已弃用的android:singleLine="True"
. 这似乎迫使 IME 选项受到尊重。
Old, Non-Working Code
旧的非工作代码
<android.support.design.widget.TextInputEditText
android:id="@+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
android:ellipsize="end"
android:hint="@string/first_name"
android:imeOptions="actionNext"
android:inputType="textCapWords"
android:maxLength="35"
android:maxLines="1" />
Working Code
工作代码
<android.support.design.widget.TextInputEditText
android:id="@+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- "
android:ellipsize="end"
android:hint="@string/first_name"
android:imeOptions="actionNext"
android:inputType="textCapWords"
android:maxLength="35"
android:maxLines="1"
android:singleLine="true" />
I'm not a fan of using a deprecated attribute, but for now it seems to get the desired result.
我不喜欢使用已弃用的属性,但就目前而言,它似乎得到了想要的结果。
回答by influx
single line deprecated so you add below code I think inputType must.
单行已弃用,因此您添加以下代码我认为 inputType 必须。
<EditText
android:inputType="text"
android:maxLines="1"
android:imeOptions="actionNext" />
回答by Ali Nawaz
Finally i have got sure solution for this issue Just add these 3 linesin your edit text and it will be working fine
最后,我对这个问题有了确定的解决方案只需在编辑文本中添加这3 行,它就会正常工作
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionDone"
Here you can add maxLinesaccording to your requirement. Do notuse singleLineas it is deprecated now. Good luck!
在这里您可以根据您的要求添加maxLines。不要使用singleLine,因为它现在已被弃用。祝你好运!
回答by paulb444
android:inputType="text"
You have to specify an inputType in order for imeOptions to function.
您必须指定 inputType 才能使 imeOptions 起作用。
回答by pavan bangalala
Key here is to set input type and imeOptions attributes
这里的关键是设置输入类型和 imeOptions 属性
<EditText
android:inputType="number"
android:maxLines="1"
android:imeOptions="actionSearch" />
回答by Sai Gopi N
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/auth_register_re_password"
android:hint="Enter Password Again"
android:imeActionLabel="login"
android:gravity="center"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"/>
回答by Zakhar Rodionov
Only this worked for me.
只有这对我有用。
Change it:
更改:
android:maxLines="1"
android:inputType="text"
android:imeOptions="actionNext"
on that:
对此:
android:singleLine="true"
android:inputType="text"
android:imeOptions="actionNext"