簡體   English   中英

Android 自動填充電話號碼未出現,僅顯示“密碼”

[英]Android Autofill Phone Number not appearing, only showing 'Passwords'

我正在嘗試在 EditText 字段中使用 Android 的自動填充功能,以在鍵盤頂部向用戶提供使用與其設備/帳戶關聯的電話號碼的建議,如下圖所示。

我嘗試將android:autofillHints="phone"android:autofillHints="phoneNumber"添加到 xml 文件中以進行布局。 這兩個選項都導致出現此“密碼”按鈕的左側屏幕截圖。 (我還在實際設備而不是模擬器上測試了這段代碼)

要查看我是否沒有正確使用自動填充或者這是設備/帳戶問題,我嘗試將代碼更改為android:autofillHints="emailAddress" 這導致正確的屏幕截圖顯示該帳戶的 email 地址(為保護隱私而編輯)。 這使我相信我的帳戶中可能沒有保存電話號碼,或者這就是為什么它默認為“密碼”的原因。

我的問題是:

  1. 為什么會出現這個“密碼”字段?
  2. 如果用戶的帳戶中沒有電話號碼,我如何隱藏“密碼”字段? (如果是這個原因)
  3. 有沒有更好的方法來 go 關於這樣做?

任何幫助將不勝感激。

自動填充結果

這是編輯文本的 xml 代碼:

<EditText
    android:id="@+id/appt_type_phone_number_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:autofillHints="phone"
    android:importantForAutofill="yes"
    android:background="@android:color/transparent"
    android:ems="10"
    android:hint="@string/enter_phone_number"
    android:inputType="phone"
    android:maxLength="16"
    android:textSize="14sp"
    android:padding="16dp"
    tools:targetApi="O"
    />
  1. 這取決於您的自動填充服務為您的應用提供的內容。

  2. & 3. 您可以通過編程方式設置 autofillHints。

     override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) binding.appt_type_phone_number_text.setAutofillHints(View.AUTOFILL_HINT_PHONE) }

參考: 針對自動填充優化您的應用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM