去除 ListView 在 setFilterText 设置过滤之后出现黑色弹框
来源:互联网 发布:国产手办淘宝哪家好 编辑:程序博客网 时间:2024/05/29 19:10
在使用 ListView 实现好友通讯录时,遇到问题:当给 ListView 的适配器 BaseAdapter 实现 Filterable 接口之后,调用:
mList.setFilterText(s.toString());
方法之后,ListView会自动出现一个显示当前过滤文字的黑色悬浮框,如图:
ListView 没有暴露相关方法去除弹框,寻找发现 ListView 父类 AbsListView 中的相关控件:
/** * Used with type filter window */ EditText mTextFilter;
相关代码 AbsListView.java:
/** * Sets the initial value for the text filter. * @param filterText The text to use for the filter. * * @see #setTextFilterEnabled */ public void setFilterText(String filterText) { // TODO: Should we check for acceptFilter()? if (mTextFilterEnabled && !TextUtils.isEmpty(filterText)) { createTextFilter(false); // This is going to call our listener onTextChanged, but we might not // be ready to bring up a window yet mTextFilter.setText(filterText); mTextFilter.setSelection(filterText.length()); if (mAdapter instanceof Filterable) { // if mPopup is non-null, then onTextChanged will do the filtering if (mPopup == null) { Filter f = ((Filterable) mAdapter).getFilter(); f.filter(filterText); } // Set filtered to true so we will display the filter window when our main // window is ready mFiltered = true; mDataSetObserver.clearSavedState(); } } }相关代码 typing_filter.xml
解决方法,通过反射设置 mTextFilter 属性达到隐藏弹框(或修改弹窗样式效果):<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2006 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><EditText xmlns:android="http://schemas.android.com/apk/res/android" android:textSize="36dp" android:textColor="#99FFFFFF" android:background="#BB000000" android:minWidth="240dip" android:maxWidth="240dip" android:padding="10dip" android:gravity="center_horizontal" android:focusable="false"/>
private void changeSearch(ListView listView) { try { Field field = listView.getClass().getSuperclass().getDeclaredField("mTextFilter"); field.setAccessible(true); EditText searchAutoComplete = (EditText) field.get(listView);// searchAutoComplete.setTextColor(getResources().getColor(android.R.color.transparent));//// searchAutoComplete.setBackgroundColor(getResources().getColor(android.R.color.transparent)); searchAutoComplete.setVisibility(View.GONE); } catch (Exception e) { e.printStackTrace(); } }
设置之后,黑色弹框成功隐藏:
阅读全文
0 0
- 去除 ListView 在 setFilterText 设置过滤之后出现黑色弹框
- 去除ListView默认出现黑色背景的方法
- listview去除底边黑色框线,去除拖动时黑屏
- 关闭Listview的setFilterText() 出现的弹出对话框
- 解决listview设置背景图片以后,拖动出现黑色的问题。
- 解决listview设置背景图片以后,拖动出现黑色的问题。
- 在滑动listview时,部分item出现背景黑色
- 自定义Dialog出现黑色背景,去除策略
- 解决android ListView设置背景后拉动时出现黑色的现象
- 解决ListView 下拉时出现黑色阴影
- ListView 滑动出现黑色边际问题
- Android APP去除启动页出现的黑色闪现
- listview在拖动时有黑色背景解决方案
- activity添加切换动画之后出现的黑色背景问题
- 拖动ListView时背景出现黑色的解决办法!
- ListView滚动时item背景出现黑色问题
- Android之ListView 点击拖动出现变黑和黑色边
- ListView /ScrollVIew 滑动出现阴影(白色或者黑色)
- MySQL数据的关系
- LDD3源码分析之访问控制
- JAVA Socket编程学习3
- ffmpeg解码框架
- 循环出一个星期的日期和星期几
- 去除 ListView 在 setFilterText 设置过滤之后出现黑色弹框
- chrome浏览器插件
- 01背包变形
- Ajax测试
- 语义分割-Pixel Deconvolutional Networks
- svn分支开发与主干合并(branch & merge)
- 网络编程初涉
- 再次探索定点数——单个信号的缩放和多个信号的叠加
- Spring task 定时任务实践