Android 搜索对话框的样式/主题
tl;dr: 应用主题中的白色文本样式被搜索对话框拾取,使搜索文本不可见。
我正在为一个看似微不足道的问题而苦苦挣扎。
我的应用程序使用深色背景,并且我使用#EEEEEE 将文本颜色调整为比标准灰色更亮。
我已经实现了一个搜索对话框(Honeycomb 之前),它运行良好,但搜索对话框中的文本会选取相同的 #EEEEEE,因此它基本上是不可见的。即使当我长按搜索文本时显示的上下文菜单也会显示#EEEEEE,因此那里的文本也是不可见的。
我正在撕扯我的头发,而且我的头发已经不多了。
风格:
<style name="master" paret="@android:style/Theme.NoTitleBar">
<item name="android:textColor">#EEEEEE</item>
<item name="android:windowNoTitle">true</item>
</style>
清单:
<application android:icon="@drawable/icon"
android:label="@string/app_label"
android:theme="@style/master"
android:hardwareAccelerated="true"
android:debuggable="true">
tl;dr: White text style in app theme being picked up by search dialog, making search text invisible.
I'm struggling mightily with what seems like a trivial issue.
My app is using a dark background, and I've tweaked the text color to be brighter than the standard gray using #EEEEEE.
I've implemented a Search Dialog (pre-Honeycomb) and it works well, but the text in the search dialog picks up the same #EEEEEE so it is essentially invisible. Even the context menu displayed when I long press the search text picks up #EEEEEE, so the text there is invisible as well.
I'm tearing my hair out, and I'm running out of hair.
Style:
<style name="master" paret="@android:style/Theme.NoTitleBar">
<item name="android:textColor">#EEEEEE</item>
<item name="android:windowNoTitle">true</item>
</style>
Manifest:
<application android:icon="@drawable/icon"
android:label="@string/app_label"
android:theme="@style/master"
android:hardwareAccelerated="true"
android:debuggable="true">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
属性
android:textColor
不适合在主题样式中使用,它主要在小部件和文本外观样式中有用。如果您想通过主题更改常规文本颜色,请使用
android:textColor*
系列属性。它们的数量相当多,并且不同的 View 使用它们的方式也不同,因此需要进行一些实验(或仔细研究 Android 源代码)才能得到正确的结果。 android.R.attr 文档列出了所有这些。查找以textColor...
开头的属性。为了让您开始,尝试这个主题,它会表现得更好,完全不影响搜索对话框的颜色,这似乎是您想要的。顺便说一句,您不需要在主题中将
android:windowNoTitle
设置为true
,因为您的父主题已经这样做了:The attribute
android:textColor
is not meant to be used inside theme styles, it is primarily useful in widget and text appearance styles.If you want to change the general text colors through a theme, use instead the
android:textColor*
family of attributes. There are quite a few of them, and different Views use them differently, so it takes a bit of experimentation (or careful studying of the Android source code) to to get it all right. The android.R.attr documentation lists them all. Look for the attributes that begin withtextColor...
.To get you started, try this theme, it will behave better by not affecting the Search Dialog colors at all, which seems to be what you want. By the way, you don't need to set
android:windowNoTitle
totrue
in your theme as your parent theme does that already:我遇到了和你一样的问题。我已经四处寻找解决方案,但似乎您无法更改对话框的文本颜色。我的解决方案是根据本教程创建自定义对话框:http://blog.androgames。 net/10/custom-android-dialog/
我根据 Android 源代码对其进行了很多扩展,始终使用相同的方法名称等以使其更容易一些。
它并不理想,但据我所知这是最好的选择...
编辑:对于您的问题可能有一个更简单的解决方案:不要将 textColor 放入主题中,而是将其放入样式中。我不知道您如何设计应用程序的样式,但我通常会创建一个“主样式”,所有其他样式都继承自(直接或间接)。然后,您可以将 textColor 放在那里,这样所有标准对话框仍将具有标准 textColor。
I got into the same problem as you. I've looked around for a solution but it seems that you just can't change the textColor of a dialog. My solution was creating a custom dialog based on this tutorial: http://blog.androgames.net/10/custom-android-dialog/
I extended this a lot based on the Android source code, always using the same method names etc to make it a bit easier.
It is not ideal, but as far as I know it's the best option...
EDIT: for your problem there might be a simpler solution: don't put the textColor into the theme, but put it in a style. I don't know how you're styling your app but I'm usually creating a "master-style" which all the others inherit from (direct or indirect). You could then put the textColor in there so all your standard dialogs will still have the standard textColor.