gpt4 book ai didi

android - 无法更改 actionbarsherlock SearchView 图标

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:30:15 25 4
gpt4 key购买 nike

当我使用以下配置时:

<item
android:id="@+id/menu_item_search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:icon="@android:drawable/ic_menu_search"
android:showAsAction="ifRoom"
android:title="@string/action_search"/>

ActionBarSherlock SearchView 对提供的 android:icon 没有反应

但如果是

android:showAsAction="ifRoom|collapseActionView"

图标已正确更改,但搜索 View 内的关闭按钮不存在。

如何更改搜索图标并在右搜索 View 角显示关闭按钮?

这是我的 AppTheme:

<style name="AppTheme" parent="AppBaseTheme">               
<item name="android:windowBackground">@color/background_window</item>
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
<item name="homeAsUpIndicator">@drawable/new_indicator</item>
<item name="android:homeAsUpIndicator">@drawable/new_indicator</item>

<!-- ActionBar (SearchView) fix -->
<item name="textColorPrimary">@color/abs__primary_text_holo_light</item>
<item name="textColorPrimaryInverse">@color/abs__primary_text_holo_dark</item>
<item name="searchDropdownBackground">@drawable/abs__search_dropdown_dark</item>
<item name="searchViewTextField">@drawable/abs__textfield_searchview_holo_dark</item>
<item name="searchViewTextFieldRight">@drawable/abs__textfield_searchview_right_holo_dark</item>
<item name="searchViewCloseIcon">@drawable/abs__ic_clear</item>
<item name="searchViewSearchIcon">@drawable/abs__ic_voice_search</item>
<item name="searchViewGoIcon">@drawable/abs__ic_go</item>
<item name="searchViewVoiceIcon">@drawable/abs__ic_voice_search</item>
<item name="searchAutoCompleteTextView">@style/Widget.Sherlock.SearchAutoCompleteTextView.DarkActionBar</item>
</style>

<style name="Widget.Sherlock.SearchAutoCompleteTextView.DarkActionBar">
<item name="android:textColor">?attr/textColorPrimaryInverse</item>
</style>

来自 list 的应用程序:

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

操作栏菜单:

<item
android:id="@+id/menu_item_search"
android:icon="@drawable/abs__ic_clear"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:showAsAction="ifRoom"
android:title="@string/action_search"/>
<item
android:id="@+id/menu_item_contact"
android:icon="@drawable/ic_action_user"
android:showAsAction="ifRoom"
android:title="@string/action_contact"/>

SearchView 菜单配置:

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_item_search).getActionView();

if (null != searchView) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
}

SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
public boolean onQueryTextChange(String newText) {
// this is your adapter that will be filtered
// adapter.getFilter().filter(newText);
return true;
}

public boolean onQueryTextSubmit(String query) {
// this is your adapter that will be filtered
// adapter.getFilter().filter(query);
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);

最佳答案

您可以通过为您的 Activity 主题设置一个属性来实现这一点。在您的 styles.xml 中添加以下几行,并确保将 MyTheme 或您想要调用的任何内容应用于您的应用程序或搜索 View 所在的 Activity 。我还添加了“searchAutoCompleteTextView”属性,如果您愿意,该属性将允许您自定义文本颜色等。

    <style name="MyTheme" parent="Theme.Sherlock">
<item name="searchViewCloseIcon">@drawable/YOUR_CLOSE_ICON</item>
<item name="searchViewSearchIcon">@drawable/YOUR_SEARCH_ICON</item>
<item name="searchAutoCompleteTextView">@style/searchTextView</item>
</style>

<style name="searchTextView" parent="Widget.Sherlock.SearchAutoCompleteTextView">
<item name="android:textColor">@android:color/white</item>
<item name="android:textColorHint">@android:color/black</item>
</style>

关于android - 无法更改 actionbarsherlock SearchView 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16971359/

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