要实现带有一个编辑文本和下拉列表框的 TextInputLayout,可以按照以下步骤进行操作:
TextInputLayout inputLayout = findViewById(R.id.inputLayout);
EditText editText = findViewById(R.id.editText);
TextInputLayout inputLayoutDropdown = findViewById(R.id.inputLayoutDropdown);
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
inputLayout.setError("This field is required");
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
inputLayout.setError(null);
}
@Override
public void afterTextChanged(Editable s) {
}
});
String[] dropdownItems = {"Item 1", "Item 2", "Item 3"};
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, dropdownItems);
autoCompleteTextView.setAdapter(adapter);
这样就实现了带有一个编辑文本和下拉列表框的 TextInputLayout。你可以根据需要添加其他功能和样式。