我的SearchView是android.support.v7.widget.SearchView和AppTheme如下所示.
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/color_accent</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
Run Code Online (Sandbox Code Playgroud)
SearchView的颜色看起来很奇怪,它的光标和底线显示为白色并快速转换为强调色,如何处理呢?我想让光标和底线保持白色.
我想从我的应用程序中删除ActionBarSherlock并将其替换为标准的ActionBarCompat.
android actionbarsherlock android-actionbar android-actionbar-compat
我想在Actionbar 的SearchView中更改闪烁光标的颜色(我使用Actionbar Sherlock来兼容).到目前为止,我已经设法改变了EditText元素的光标颜色.这个SO帖子帮助我完成了这个,我用于EditText的样式如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
红色光标看起来像这样:
<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>
Run Code Online (Sandbox Code Playgroud)
我确实看了一下SearchView小部件的实现,虽然它使用AutoCompleteTextView进行文本输入.由于AutoCompleteTextView是从EditText小部件派生的,我不太明白为什么样式适用于EditText而不适用于AutoCompleteTextView(因此也适用于SearchView).
有没有人设法改变SearchView小部件中光标的颜色?
我知道这个问题已经发布了数百万次,但我无法为我的案例找到一个有效的解决方案.
我需要更改searchView的光标颜色.我没有searchView的xml定义,我以编程方式使用它.
这是我的代码:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_contacts, menu);
SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView();
search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
return true;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个:
import android.support.v7.widget.SearchView;
谢谢