Android搜索框之PopupWindow+ListView实现

PopupWindow+ListView实现Android搜索框


1:布局文件(EditText+ImageView)
2:   自定义ListView适配器
SearchAdapter adapter = new SearchAdapter(searchs,
MainActivity.this);
3:新建一个ListView,并根据EditText内容初始化适配器,并加载listView
lv.setAdapter(adapter);
4:创建一个PopupWindow,并初始化,设置属性
popupWindow = new PopupWindow(lv, et.getWidth(),
LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(false);
popupWindow.setBackgroundDrawable(new ColorDrawable());
5:显示
popupWindow.showAsDropDown(et);

源码参考:点击打开链接

你可能感兴趣的:(Android)