gpt4 book ai didi

android - SearchView 不扩展全宽

转载 作者:IT老高 更新时间:2023-10-28 23:40:33 25 4
gpt4 key购买 nike

我有下一个结果:

enter image description here

menu.xml

<?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>

my_search_view.xml

<?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"/>

Activity

@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(关闭操作)位于屏幕右侧。

最佳答案

MenuItemCompat 的 SearchView 有一个名为 maxWidth 的属性。以下是诀窍:

searchView.setMaxWidth( Integer.MAX_VALUE );

关于android - SearchView 不扩展全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31456102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com