在搜索查看自定义光标颜色 [英] Custom cursor color in SearchView

查看:674
本文介绍了在搜索查看自定义光标颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变闪烁光标的颜色在搜索查看在动作条(我使用的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>

我也来看看在搜索查看小工具的实施,因为我虽然它使用的是<一href="http://developer.android.com/reference/android/widget/AutoCompleteTextView.html">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>

这篇关于在搜索查看自定义光标颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆