我有下一个结果:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:actionLayout="@layout/my_search_view"
android:icon="@android:drawable/ic_menu_search"
android:title="Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView"/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<SearchView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxWidth="10000dp"/>
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setQueryHint("Поиск");
searchView.setOnQueryTextListener(this);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
searchView.setLayoutParams(params);
searchView.setIconified(false);
MenuItemCompat.expandActionView(searchItem);
return super.onCreateOptionsMenu(menu);
}
我希望X(关闭 Action )位于屏幕的右侧。
最佳答案
MenuItemCompat的SearchView具有一个名为maxWidth的属性。以下是窍门:
searchView.setMaxWidth( Integer.MAX_VALUE );
关于android - SearchView不会扩展全宽,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31456102/