2010-01-07 51 views

回答

33

android:password已被棄用,但據我所知是唯一的出路,因爲android:inputType="phone|textPassword"被忽略......

<EditText 
    android:id="@+id/EditText01" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:password="true" 
    android:inputType="phone" /> 
+0

啊,有趣。我沒有看到它被棄用。以下是提及'inputType'的文檔(如羅馬提到的):http://developer.android.com/reference/android/R.attr.html#password – 2010-01-07 02:19:21

+1

作爲一個小補充,對於那些想要做代碼中的東西: editText.setInputType(InputType.TYPE_CLASS_PHONE); editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); – 2014-01-23 03:11:22

+2

inputType =「numberPassword」可能是最好的選擇,但它只適用於如果你的應用程序的最小SDK> = 3.0(蜂窩) – k2col 2014-05-27 20:43:12

0

我沒有試過,但有可能在兩個像這樣結合:

android:inputType="textPassword|phone" 

因爲inputType可以採取多個值。

+0

它不起作用。 EditText忽略textPassword,只是設置爲電話 – Portablejim 2010-01-07 02:48:27

+1

對不起,我的答案只是一個受過教育的猜測,沒有測試.. dtmilano的片段看起來是正確的路要走。 – 2010-01-07 20:00:40

1

這個問題可以不使用過時android:password來解決。看到我的回答here

+0

你認爲android:密碼是如何工作的? ;)是的,它是不推薦使用的XML屬性,但是在呈現屬性時在運行時執行了哪些代碼? – 2014-01-23 03:20:25

2

我還沒有找到適合此問題的解決方案。 dtmilano接受的解決方案並不完全適用。如果EditText專注於具有全屏幕鍵盤的橫向模式,則數字仍然以明文形式顯示,而不是屏蔽。

我花了顯著時間通過實際TextView的代碼去,這是一個問題的原因是,他們明確地檢查,對InputType.TYPE_CLASS_TEXT的的inputType,如果我沒有記錯,TYPE_MASK_CLASS。所以如果你在這些邊界內包含任何其他InputType(我認爲TYPE_CLASS_TEXT和TYPE_MASK_CLASS使用的範圍是第一個字節),那麼它將不會被識別爲需要掩蔽的密碼。

我知道我說的很混亂。實際的代碼很容易混淆。老實說,我對TextView的代碼感到非常震驚。這是一團亂七八糟的事情,到處都是硬編碼的檢查。可怕的編碼習慣會導致這樣的問題。

5

我相信這是你想要的嗎?

android:inputType="numberPassword" 

編輯:在這個問題(2010年),這可能尚未在API中,但對於當代的發展,它的可用時間。