问题描述
我已经与方向沿以下为搜索查看和对话实现。两者都低于可见。上有这样专注于定制搜索框的许多问题,但很少是有关自定义的建议的用户界面。 (那些是关于颜色/字体的偏多,默认值这是对我很好。)我想是能够扩大的建议采取了屏幕的整个宽度。有什么办法可以自定义使用任一对话框或搜索查看实施的宽度。我想preFER不使用库除非这是唯一的选择。如果这是可能的,或者容易与该细的实现之一
I've been following along with the directions here for both SearchView and dialog implementations. Both are visible below. There are many questions on SO that focus on customizing the search box, but few that are about customizing the UI of the suggestions. (The ones that do are about color/font, the defaults for which are fine for me.) I would like to be able to widen the suggestions to take up the whole width of the screen. Is there any way to customize the width using either dialog or SearchView implementations. I'd prefer not to use a library unless that is the only option. If this is possible or easier with one of the implementations that is fine.
下面就是对话框实施的样子对我来说:
Here's what the dialog implementation looks like for me:
下面有什么搜索查看执行的样子对我来说:
Here's what the SearchView implementation looks like for me:
推荐答案
这是你如何能做到这一点:
第1步:
This is how you can do it :Step 1 :
刚刚创建任何你想用回收视图或扩展列表或列表的布局。
Just create a layout with recycler view or expandable list or list whichever you want to use.
第二步:在您的活动(CityActivity),你需要这样做:
Step 2 : In you activity (CityActivity) you need to do this :
- 创建一个这样的处理程序:
私有静态类SearchHandler扩展了Handler {
private static class SearchHandler extends Handler {
private WeakReference<CityActivity> mTarget;
SearchHandler(CityActivity target) {
mTarget = new WeakReference<>(target);
}
public void setTarget(CityActivity target) {
mTarget.clear();
mTarget = new WeakReference<>(target);
}
@Override
public void handleMessage(final Message msg) {
if (msg.what == CityActivity.TRIGGER_SEARCH) {
CityActivity activity = mTarget.get();
activity.makeRequest(mSearchText.trim());
}
}
}
2.把textchangelistener你searchedittext
}2. put textchangelistener on your searchedittext
public void setTextChangeListener() {
searchView.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) {
mSearchText = searchView.getText().toString();
if (!mSearchText.trim().isEmpty()) {
handler.removeMessages(CitySelectionActivity.TRIGGER_SEARCH);
handler.sendEmptyMessageDelayed(CityActivity.TRIGGER_SEARCH,
CityActivity.SEARCH_TRIGGER_DELAY_IN_MS);
} else {
suggestList.clear();
fillAnything();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
在这里建议名单是提供给您的列表
Here suggest list is the data that is given to your list of
这篇关于Android的搜索:自定义布局的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!