我希望你能帮助我解决我现在面临的问题.
我使用TextInputEditText创建了一个自定义搜索视图,它实际上非常简单,并且除了5.1(Lollipop)之外的所有Android版本都能正常工作,EditText在写入时甚至不会隐藏提示甚至显示光标,文本也不是可见.
我已经尝试过我所知道的一切,但我无法想象它会是什么.
非常感谢您的参与.
这是我的自定义类视图:
public class CustomSearchView extends RelativeLayout {
@BindView(R.id.csvIcon) ImageView csvIcon;
public @BindView(R.id.csvEditText) TextInputEditText editText;
public CustomSearchView(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_search_view, this, true);
ButterKnife.bind(this);
}
public CustomSearchView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_search_view, this, true);
ButterKnife.bind(this);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CustomSearchView,
0, 0);
String hintText = typedArray.getString(R.styleable.CustomSearchView_hintText);
try {
int max = typedArray.getInteger(R.styleable.CustomSearchView_csv_length, 17);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(max)});
editText.setInputType(typedArray.getInt(R.styleable.CustomSearchView_android_inputType, InputType.TYPE_CLASS_TEXT));
editText.setHint(hintText);
csvIcon.setImageDrawable(typedArray.getDrawable(R.styleable.CustomSearchView_csv_icon));
} catch (Exception e) …Run Code Online (Sandbox Code Playgroud) java android android-edittext android-5.0-lollipop android-textinputedittext