Android SearchView-更改光标颜色

时间:2019-03-11 17:21:06

标签: java android search themes

我试图更改实例化并添加到操作栏中的SearchView的光标颜色,如下所示:

set.seed(111)
mydata <- sample(1:100, 100, 1)
(nDuplicates <- length(mydata) - length(unique(mydata)))

> (nDuplicates <- length(mydata) - length(unique(mydata)))
[1] 35

Xml代码:

MenuItem findItem = menu.findItem(R.id.menu_action_search);
        searchView = (SearchView) findItem.getActionView();

我的活动具有这样的工具栏:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    >

      <item android:id="@+id/menu_action_search"
          android:title="Search"
          android:icon="@drawable/ic_search_white"
          app:showAsAction="collapseActionView|always"
          app:actionViewClass="android.support.v7.widget.SearchView" />

</menu>

是否可以覆盖现有样式并更改自动完成文本视图的光标颜色?

2 个答案:

答案 0 :(得分:3)

您可以执行以下步骤来更改光标颜色。

步骤1:定义您自己的光标可绘制对象,该对象位于>>> df Security Symbol SEC filings GICS Sector 0 Agilent Technologies Inc A reports Health Care 1 American Airlines Group AAL reports Industrials 2 Advance Auto Parts AAP reports Consumer Discretionary 3 Apple Inc. AAPL reports Information Technology 4 AbbVie Inc. ABBV reports Health Care >>> df.loc[df['GICS Sector'] == 'Health Care'] Security Symbol SEC filings GICS Sector 0 Agilent Technologies Inc A reports Health Care 4 AbbVie Inc. ABBV reports Health Care 文件夹中。

my_cursor.xml

res/drawable

步骤2:将此代码添加到<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#0f0"/> <size android:width="1dp"/> </shape> 中。

onCreateOptionsMenu

答案 1 :(得分:0)

尝试找到它的默认主题,然后通过您自己的主题对其进行扩展,然后覆盖android:textCursorDrawable属性。

This link可能会帮助您:)

相关问题