2013-03-20 7 views
5

アクションバーのSearchView(私はアクションバーSherlockを使用しています)の点滅カーソルの色を互換性のために変更します。今まで私はEditText要素のカーソルの色を変更することができました。 This SO postはそれを達成するために私を助け、私はのEditTextのために使用しているスタイルは次のようになります。SearchViewのカスタムカーソルの色

<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> 

赤いカーソルが次のようになります。私はの実装を見てみました

<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> 

SearchViewウィジェットを使用していますが、テキスト入力には AutoCompleteTextViewが使用されています。 AutoCompleteTextViewはEditTextウィジェットから派生したものなので、スタイルがEditTextでは機能しているが、AutoCompleteTextViewでは(そしてSearchViewでは)なぜ機能していないのか分かりません。

誰かがSearchViewウィジェットのカーソルの色を変更できましたか?

答えて

7

私はちょうど動作する解決策を見つけました。私は

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

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

を置き換え、それはこのようになりますように、私のテーマを変更:あなただけの属性アンドロイド上書きするために必要な

<style name="CustomTheme" parent="Theme.Sherlock.Light"> 
    ... 
    <item name="searchAutoCompleteTextView">@style/SearchViewStyle</item> 
    ... 
</style> 
+0

:SearchAutoCompleteTextViewのテーマにtextCursorDrawableをし、それはうまくいくはずだった。 – MaTriXy

+0

うん、それは私がやったことだ。ありがとう – mvieghofer

+0

デフォルトの色を変更することはできますが、ドロアブルは変更できませんか?私はcolorControlActivatedを使用しましたが、これは単なるテキストキャレットの色よりも変わります... –

関連する問題