【发布时间】:2017-12-18 07:33:47
【问题描述】:
查看自动填充文档here
.特别是 AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE 常量。所以我设置了自动填写奥利奥模拟器,它非常适合获取存储的用户信用卡信息。但问题是到期日期来自“09/19”格式的自动填充,但我需要它作为“09/2019”。从文档中说我们可以覆盖 getAutofillType() to return AUTOFILL_TYPE_DATE.
我不明白?因为这样它会返回纪元时间'日期给我。我如何让它以我想要的格式返回日期?
Google 提供了如何执行此操作的说明:
您可以通过覆盖以下方法为视图定义日期自动填充值:
- getAutofillType() 返回 AUTOFILL_TYPE_DATE。
getAutofillValue() 返回一个日期自动填充值。
autofill(AutofillValue) 期望数据自动填充值。
鉴于这是我迄今为止在自定义编辑文本中的内容:
public class AutoFillDateFormEditText extends AppCompatEditText{
public AutoFillDateFormEditText(Context context) {
super(context);
}
public AutoFillDateFormEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AutoFillDateFormEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public int getAutofillType() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return AUTOFILL_TYPE_DATE;
}
else return super.getAutofillType();
}
@Override
public void autofill(AutofillValue value) {
super.autofill(value); //what goes here ? im lost
}
@Nullable
@Override
public AutofillValue getAutofillValue() {
return //what should i return here ????
}
}
即使我在推荐的覆盖上保留断点,只有 getAutofillType() 会遇到断点,其余被覆盖的方法不会被命中。我下载了谷歌示例应用程序“自动填充示例”并尝试了它,但日期也不起作用。所以我不认为是我做错了什么。我正在测试奥利奥模拟器 api 26 Nexus 6P。
这里有相同的说明:https://developer.android.com/guide/topics/ui/controls/pickers.html#PickerAutofill
但目前似乎无法使用系统自动填充服务(至少在模拟器上)。
【问题讨论】: