Android 是否关闭EditText的自动建议?
是否有一种方法可以通过编程方式关闭在键入EditText时弹出的自动建议列表?好的,问题是-在Eclipse中,您没有收到名为:textNoSuggestion的标志的建议 您不能在main.xml(您设计UI的地方)中设置它,因为无法识别inputType的属性。因此,您可以使用int const在代码中设置它:Android 是否关闭EditText的自动建议?,android,android-edittext,Android,Android Edittext,是否有一种方法可以通过编程方式关闭在键入EditText时弹出的自动建议列表?好的,问题是-在Eclipse中,您没有收到名为:textNoSuggestion的标志的建议 您不能在main.xml(您设计UI的地方)中设置它,因为无法识别inputType的属性。因此,您可以使用int const在代码中设置它: EditText txtTypeIt = (EditText) this.findViewById(R.id.txtTypeIt); txtTypeIt.setInputType(5
EditText txtTypeIt = (EditText) this.findViewById(R.id.txtTypeIt);
txtTypeIt.setInputType(524288);
谢谢你帮我找出这个问题的答案。我有同样的问题,但我仍然想在XML文件中设置这个选项,所以我做了更多的研究,直到我自己找到答案 将这一行添加到编辑文本中
android:inputType="textFilter"
这里有一个提示。如果您希望能够使用“回车”键,请使用此行
你最好读一读
这将对您有所帮助。您只需使用EditText的
setThreshold()
方法即可。如果不想显示预测,请将阈值设置为100。如果要重新激活显示预测,请根据需要将其设置回小整数,如1或2
android:inputType="textVisiblePassword"
工作起来很有魅力我发现摆脱自动完成最可靠的方法是使用
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
在EditText控件上。正如charlie在本页的不同回答中所述
android:inputType="textVisiblePassword"
是此标志的XML版本
您可以将此标志与
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
我一直在使用InputType.TYPE\u TEXT\u FLAG\u NO\u建议,但没有InputType.TYPE\u TEXT\u VARIATION\u VISIBLE\u密码,这在大多数手机上都适用,但后来我遇到了一款三星手机,我仍然可以自动完成
建议使用InputType.TYPE\u TEXT\u VARIATION\u VISIBLE\u密码
我试过这个(和InputType.TYPE\u TEXT\u FLAG\u NO\u SUGGESTIONS一起),它成功了。您可以看到,为什么即使是一部可能不接受您不希望自动完成提示的手机也必须允许在密码字段中禁用它。我们屏住呼吸,这可能是从这些手机中得到我们想要的东西的最好方式
在我的一些设备上,这个标志稍微改变了字体——最明显的是为了更清楚地区分零(0)和Oh(O),这显然对显示密码很重要。但至少它起作用了,而且新字体也并非没有吸引力
尽管我发现这一建议的帖子很旧,但我测试的手机是最近的——一款三星Galaxy Note II(SPH-L900)的Sprint Android 4.1.2。选择的键盘是“三星键盘”,显然,当客户从Sprint收到它时,这是这款手机的默认键盘。因此,这一问题显然已经持续多年,至少在一些重要的三星系列手机上
对于像我这样没有三星测试设备的人来说,这可能是一个重要的信息。因为这仍然是一个问题,我将发布这个答案。android:inputType=“textVisiblePassword”可以工作,但这是不可取的,首先是因为这是输入的错误陈述,其次是因为它禁用了手势输入
android:inputType="text|textNoSuggestions"
相反,我必须同时使用标记textNoSuggestions和textFilter。这两种方法都不起作用
android:inputType="textCapSentences|textFilter|textNoSuggestions"
这些句子是出于其他原因。但是这个inputType保留了滑动输入并禁用了建议工具栏 方法:
如果已经设置了一些标志,则:
我在运行4.4.4的三星手机上得到了这个东西。这解决了我的问题
android:inputType="text|textVisiblePassword|textNoSuggestions"
对于android版本8.0或更高版本,此代码不起作用 对于autocomplete textview,此代码也不起作用,因此我建议您使用以下代码来禁用8.0或更高版本的android vesrion中的自动建议使用edittext android:importantForAutofill=“no”
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:focusable="false"
android:imeOptions="actionDone"
android:maxLength="80"
android:maxLines="1"
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorBlack"
android:importantForAutofill="no"
android:textSize="@dimen/_12sdp"
app:bFontsEdt="light" />
对于像这样的自动完成文本视图,使用此字段禁用自动建议android:importantForAutofill=“no”:
<AutoCompleteTextView
android:id="@+id/autocompleteEditTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_3sdp"
android:layout_marginTop="@dimen/_5sdp"
android:background="@null"
android:imeOptions="actionDone"
android:singleLine="true"
android:text=""
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorGrayDark"
android:importantForAutofill="no"
android:textSize="@dimen/_12sdp" />
您可以使用以下方法解决此问题:
android:importantForAutofill="no"
Android O具有支持字段自动填充的功能,只需在xml中使用此功能,它将禁用自动填充提示
android:importantForAutofill="no"
android:inputType="none|textNoSuggestions"
请注意,“textNoSuggestions”仅适用于API 5及以上版本。@gyller您见过API小于5的设备吗?我的用户中有0.23%在1.6(API级别4)上:)尽管你失去了回车键。如果您希望能够使用android:inputType=“textNoSuggestions | textMultiLine”,它会禁用建议,但仍会显示建议行(其中有一个麦克风选项)。这就完成了。setInputType(InputType.TYPE\u TEXT\u FLAG\u NO\u SUGGESTIONS);同意,使用常量而不是value@kape123您无法在xml中设置android:inputType=“textNoSuggestions”,因为您的构建目标低于5 API请注意,对于某些三星手机,标准键盘自动完成功能不会被inputType.TYPE\u TEXT\u FLAG\u NO\u建议关闭。一个人建议在这篇相当老的帖子中使用InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:在三星S3上使用今天的固件不起作用。哦。@SargeBorsch:你是说类型\文本\变体\可见\密码以及类型\文本\标志\否\建议仍然在S3上执行自动完成吗?我知道,你在用普通键盘吗?我没有S3,但过去曾在S3上尝试过我的应用程序(使用上述方法),但没有自动完成。我有一个运行Android 4.4(Cyanogenmod)的S4,但它也不能自动完成。@SargeBorsch:如果你想在S3上尝试使用上述方法的应用程序,这里是我的:我很想知道该应用程序底部的Check Word字段(使用上述标志)是否尝试在你的设备上自动完成。TIA.谢谢,很快就会查出来>“你是说那种类型的文字变体吗?”
android:inputType="text|textVisiblePassword|textNoSuggestions"
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:focusable="false"
android:imeOptions="actionDone"
android:maxLength="80"
android:maxLines="1"
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorBlack"
android:importantForAutofill="no"
android:textSize="@dimen/_12sdp"
app:bFontsEdt="light" />
<AutoCompleteTextView
android:id="@+id/autocompleteEditTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_3sdp"
android:layout_marginTop="@dimen/_5sdp"
android:background="@null"
android:imeOptions="actionDone"
android:singleLine="true"
android:text=""
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorGrayDark"
android:importantForAutofill="no"
android:textSize="@dimen/_12sdp" />
// 100% correct & tested
txtKey = (EditText) view.findViewById(R.id.txtKey);
txtKey.setPrivateImeOptions("nm");
txtKey.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
txtKey.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
}
android:importantForAutofill="no"
android:importantForAutofill="no"
android:inputType="none|textNoSuggestions"