在搜索查看自定义光标颜色自定义、光标、颜色

由网友(心灵老鸭汤)分享简介:我想改变闪烁光标的颜色在搜索查看在动作条(我使用的ActionBar福尔摩斯的兼容性)。到现在为止我已经成功地改变光标的颜色为一的EditText元素。 这SO帖子帮助我实现这一点,我使用的样式为EditText上看起来像这样的:I want to change the color of the blinking c...

我想改变闪烁光标的颜色在搜索查看在动作条(我使用的ActionBar福尔摩斯的兼容性)。到现在为止我已经成功地改变光标的颜色为一的EditText元素。 这SO帖子帮助我实现这一点,我使用的样式为EditText上看起来像这样的:

I want to change the color of the blinking cursor in a SearchView in the Actionbar (I'm using Actionbar Sherlock for compatibility). Until now I've managed to change the color of the cursor for a EditText element. This SO post helped me to accomplish that and the style I'm using for the EditText looks like this:

<style name="CustomTheme" parent="Theme.Sherlock.Light">
    <item name="android:editTextStyle">@style/edittext_style</item>
</style>

<style name="edittext_style" parent="@android:style/Widget.EditText">
    <item name="android:textCursorDrawable">@drawable/red_cursor</item>
</style>

红色指针看起来是这样的:

The red cursor looks like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
       android:shape="rectangle" >
    <gradient android:startColor="@color/darkRed" 
              android:endColor="@color/darkRed" />
    <size android:width="1dp" />
</shape>

我也来看看在搜索查看小工具的实施,因为我虽然它使用的是AutoCompleteTextView文本输入。由于AutoCompleteTextView是从的EditText小部件来源,我真的不明白为什么风格正在为EditText上而不是为AutoCompleteTextView(因此对于搜索查看)。

I did take a look at the implementation of the SearchView widget and as I though it uses an AutoCompleteTextView for the text input. Since the AutoCompleteTextView is derived from the EditText widget, I don't really understand why the style is working for the EditText but not for the AutoCompleteTextView (and therefore for the SearchView).

有没有人管理,以改变光标的颜色在搜索查看小工具?

Has anyone managed to change the color of the cursor in the SearchView widget?

推荐答案

我刚刚发现了一个解决方案,工程。我取代了

I just found a solution that works. I replaces the

<style name="edittext_style" parent="@android:style/Widget.EditText">
    <item name="android:textCursorDrawable">@drawable/red_cursor</item>
</style>

<style name="SearchViewStyle" parent="Widget.Sherlock.Light.SearchAutoCompleteTextView">
    <item name="android:textCursorDrawable">@drawable/red_cursor</item>
</style>

和修改了我的主题,所以它看起来是这样的:

and modified my theme so that it looks like this:

<style name="CustomTheme" parent="Theme.Sherlock.Light">
    ...
    <item name="searchAutoCompleteTextView">@style/SearchViewStyle</item>
    ...
</style>
阅读全文

相关推荐

最新文章