构建autofill service
对于在显示列表中的数据填充,需要app在继承AutofillService时,在重写onFillRequest()数据请求时进行数据装在载,这里指对onFillRequest做一些解释;

public class MyAutofillService extends AutofillService{.....@Overridepublic void onFillRequest(FillRequest request, CancellationSignal cancellationSignal,        FillCallback callback) {    //创建数据集;    FillResponse.Builder response = new FillResponse.Builder();    for (int i = 1; i <= NUMBER_DATASETS; i++) {            Dataset.Builder dataset = new Dataset.Builder();            //创建RemoteViews.插入xml布局并填写数据;            RemoteView presentation =new  RemoteViews(getApplicationContext().            .packageName,R.layout.multidataset_service_list_item);            //给这个布局Item显示一个名字,remoteViewsText;            presentation.setTextViewText(R.id.text, text);            //把新的data添加到数据集;            response.addDataset(dataset.build());        }         //最后通知android系统,完成该服务        callback.onSuccess(response.build());   }}

接下来我们来说一下关于EditText的一些相关使用和数据;
1.AutofillHints和setImportantForAutofill
关于Autofill 在view上的两个关键属性autofillHints和setImportantForAutofill,autofillHints:在点击自动填充后,显示提示列表,如果不做处理或不添加属性则不会出现提示列表;
setImportantForAutofill:这个属性主要是用于在打开带有EdiText或TextView等一些View时,采用此属性进行设置,是否自动弹出或手动弹出,
activity_layout.xml定义;

MainActivity.java定义

public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    EditText et=findViewById(R.id.username);   //点击自动填充弹出提示列表    et.setAutofillHints(View.AUTOFILL_HINT_PASSWORD);  //用来设置是否自动弹出提示列表    et.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);    }}

view.setAutofillHints() 方法来设置标记,相关值都是View类(api 26版本以上)中定义的一些String类型常量;

AUTOFILL_HINT_NAME 用户真名AUTOFILL_HINT_PASSWORD 用户密码AUTOFILL_HINT_PHONE 电话号码AUTOFILL_HINT_EMAIL_ADDRESS 邮箱地址AUTOFILL_HINT_POSTAL_CODE 邮寄编号AUTOFILL_HINT_POSTAL_ADDRESS 邮寄地址AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY 信用卡到期日AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE 信用卡到期日期AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH 信用卡到期月AUTOFILL_HINT_CREDIT_CARD_NUMBER 信用卡卡号AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE 信用卡安全密码AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR 信用卡到期年AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY 信用卡到期日

setImportantForAutofill()相关值都是View类(api 26版本以上);

    //Automatically determine whether a view is important for autofill.    public static final int IMPORTANT_FOR_AUTOFILL_AUTO = 0x0;    //The view is important for autofill, but its children (if any) will not be traversed.    public static final int IMPORTANT_FOR_AUTOFILL_YES = 0x1;    //The view is not important for autofill, but its children (if any) will be traversed.    public static final int IMPORTANT_FOR_AUTOFILL_NO = 0x2;    //The view is important for autofill, but its children (if any) will not be traversed.    public static final int IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS = 0x4;    //The view is not important for autofill, and its children (if any) will not be traversed.    public static final int IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS = 0x8;

android N 新增API Autofill

官方Demo;
https://github.com/googlesamples/android-AutofillFramework
https://download.csdn.net/download/xiao_yuanjl/10862116

更多相关文章

  1. TextView中ellipsize属性
  2. android:name 的秘密
  3. Android(安卓)中解析JSON形式的数据
  4. Android(安卓)Layout XML属性
  5. Android(安卓)属性动画(Property Animation) 完全解析 (上)
  6. Android基础类之BaseAdapter
  7. This tag and its children can be replaced by one and a comp
  8. [Android(安卓)Pro] 使用CursorLoader异步加载数据 from 3.0
  9. mybatisplus的坑 insert标签insert into select无参数问题的解决

随机推荐

  1. 探讨微软的混合云
  2. windows10打不开应用商店
  3. 探讨阿里数加平台
  4. xp sp3升级包
  5. 大数据三种典型云服务模式
  6. 如何一举拿下大厂Offer面经(附面试题)
  7. 微软大数据领域优势分析
  8. 华纳云:香港IP地址更换需要注意的事项
  9. 大数据仓库-kudu
  10. PDO连接数据库实例