Android 如何在 Actionbar 中设置 SearchView 的样式?

发布于 2025-01-03 21:55:36 字数 229 浏览 2 评论 0原文

我需要更改 ActionBarSearchView 的样式。特别是,如果可能的话,我需要更改文本提示颜色和 SearchView 图标。我如何在 XML 中实现这一点(在 XML 中是否可能)?

如果这是不可能的,我如何使用自定义视图轻松地重新创建类似的行为? SearchView 的关闭/展开行为对我来说特别有用。

I need to change the style of my SearchView in my ActionBar. In particular I need to change the text hint color and the SearchView icons if possible. How can I accomplish this in XML (is it even possible in XML)?

If this isn't possible, how can I easily recreate similar behavior with a custom view? The close/expand behavior of the SearchView is particularly useful for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

太阳公公是暖光 2025-01-10 21:55:36

您是否尝试过类似的操作(使用 ActionBarSherlock):

AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white));

它对我来说效果很好。

Have you tried something like this (With ActionBarSherlock):

AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(R.color.white));
searchText.setTextColor(getResources().getColor(R.color.white));

It works fine for me.

最冷一天 2025-01-10 21:55:36

看起来您可能需要为您的搜索操作提供自定义布局。我还没有找到任何有关修改默认 SearchView 的文档。但这确实允许关闭/展开行为。

http://developer.android.com/guide/topics/ui/ actionbar.html#ActionView

相关问题:

It looks like you may need to supply a custom layout for your search action. I haven't been able to find any documents that talk about modifying the default SearchView. But this does allow the close/expand behavior.

http://developer.android.com/guide/topics/ui/actionbar.html#ActionView

Related questions:

安静被遗忘 2025-01-10 21:55:36

您需要创建一个新主题并在清单文件中使用它。

<style name="Theme.Test" parent="@style/Theme.AppCompat.Light">
   <item name="searchViewAutoCompleteTextView">@style/Theme.Test.SearchField</item>
</style>

<!-- Search edit text -->
<style name="Theme.Test.SearchField" parent="@style/Widget.AppCompat.Light.AutoCompleteTextView">
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHint">@color/white</item>
</style>

这对我来说效果很好。

You need to create a new theme and use it in manifest file.

<style name="Theme.Test" parent="@style/Theme.AppCompat.Light">
   <item name="searchViewAutoCompleteTextView">@style/Theme.Test.SearchField</item>
</style>

<!-- Search edit text -->
<style name="Theme.Test.SearchField" parent="@style/Widget.AppCompat.Light.AutoCompleteTextView">
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHint">@color/white</item>
</style>

It worked fine for me.

南…巷孤猫 2025-01-10 21:55:36

正确的答案是使用您自己的自定义样式来重载操作栏小部件样式。对于带有深色操作栏的全息光,请将其放入您自己的样式文件中,例如 res/values/styles_mytheme.xml

<style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarWidgetTheme">@style/Theme.MyTheme.Widget</item>
    <!-- your other custom styles -->
</style>

<style name="Theme.MyTheme.Widget" parent="@android:style/Theme.Holo">
    <item name="android:textColorHint">@android:color/white</item>
    <!-- your other custom widget styles -->
</style>

确保您的应用程序使用主题自定义主题,如 在此处输入链接描述

The right answer is to overload the action bar widget style with your own custom style. For holo light with dark action bar, put this in your own styles file such as res/values/styles_mytheme.xml:

<style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarWidgetTheme">@style/Theme.MyTheme.Widget</item>
    <!-- your other custom styles -->
</style>

<style name="Theme.MyTheme.Widget" parent="@android:style/Theme.Holo">
    <item name="android:textColorHint">@android:color/white</item>
    <!-- your other custom widget styles -->
</style>

Make sure your application is using theme custom theme as described in enter link description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文