ActionBar搜索视图,如何处理左箭头点击?

时间:2016-10-07 22:11:08

标签: android event-handling searchview

这是图片: enter image description here

如何处理左箭头点击? 我通过意图进行了搜索,没关系:

@Override
protected void onNewIntent(Intent intent) {
    handleIntent(intent);
}

private void handleIntent(Intent intent) {
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        mFilter = intent.getStringExtra(SearchManager.QUERY);
        ...search query
    }
}

和我的关闭按钮代码:

ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn);
    closeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
...
}

如何处理左箭头?

2 个答案:

答案 0 :(得分:0)

SearchView小部件中有OnCloseListener

searchView.setOnCloseListener(new SearchView.OnCloseListener() {
    ...
});

答案 1 :(得分:0)

// When using the support library, the setOnActionExpandListener() method is
// static and accepts the MenuItem object as an argument
MenuItemCompat.setOnActionExpandListener(menuItem, new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
    // Do something when collapsed
    return true;  // Return true to collapse action view
}

@Override
public boolean onMenuItemActionExpand(MenuItem item) {
    // Do something when expanded
    return true;  // Return true to expand action view
}
});

这是从这里开始的:https://stackoverflow.com/a/18186164/4200187