試試這個:eText_key1.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
或者,你可以把下面的EditText上的XML定義:android:inputType="textFilter"
。
編輯:
下面是一個例子,只要確保你定義在你切換邏輯和設置你的XML佈局,或初始化你的onCreate輸入類型:
setContentView(R.layout.edittext);
Button switchButton = (Button) findViewById(R.id.switchbutton);
final EditText editText = (EditText) findViewById(R.id.password);
switchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (passwordShouldBeVisible) {
editText.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
} else {
editText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD
| InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
}
});
和這裏的XML文件我使用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text|textFilter"/>
<Button
android:id="@+id/switchbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Switch" />
</LinearLayout>
對不起,這不適合我的HTC Desire工作:-(我只是邏輯與的那兩個:'etext_key1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);' – Till
奇怪......我添加了一個例子在我的設備上正常工作檢查您是否在初始設置輸入類型時以及在何時切換輸入類型 – Craigy
只需再次嘗試一次虛擬模擬器正確地禁用了自動完成功能,而真正的Desire則嘗試糾正我的輸入。 ? – Till