【问题标题】:how can I Change the hint text color of SearchView如何更改 SearchView 的提示文本颜色
【发布时间】:2018-02-01 11:12:47
【问题描述】:

如何更改 SearchView 的提示文字颜色?

<android.support.v7.widget.SearchView
        android:id="@+id/search"
        style="@style/SearchViewStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColorHint="@android:color/black"
        android:clickable="true"
        android:focusable="true"/>

使用 thisandroid:textColorHint="@android:color/black" 没有任何帮助表示感谢

【问题讨论】:

  • @Abhishekkumar 该示例不是支持库,可能是操作栏 sherlock。
  • 你能发布你的代码@MohdQasim
  • @Abhishekkumar 我用 xml 代码编辑了我的问题
  • 你也可以发布你的searchview的java代码@MohdQasim

标签: android material-design searchview


【解决方案1】:

初始化它

SearchView searchView = findViewById(R.id.viewSearch);
    searchView.setQueryHint("Search For Anything"); ---hint that is to be displayed
    LinearLayout first = (LinearLayout)searchView.getChildAt(0);
    LinearLayout second = (LinearLayout)first.getChildAt(2);
    LinearLayout third = (LinearLayout)second.getChildAt(1);
**strong text**    
SearchView.SearchAutoComplete autoComplete = (SearchView.SearchAutoComplete)third.getChildAt(0);

-------这将改变查询提示颜色

autoComplete.setHintTextColor(getResources().getColor(R.color.gray2));

-----这将改变查询文本的颜色

autoComplete.setTextColor(getResources().getColor(R.color.black));

【讨论】:

    【解决方案2】:

    是的,我通过在代码中使用休闲更改来解决我的问题

     search = (SearchView) rootView.findViewById(R.id.search);
        // search.setQueryHint("search");
        searchEditText = (EditText)search.findViewById(android.support.v7.appcompat.R.id.search_src_text);
        searchEditText.setTextColor(getResources().getColor(R.color.colorPrimary));
        searchEditText.setHintTextColor(getResources().getColor(R.color.colorPrimary));
        searchEditText.setHint("search here for quick access");
    

    我评论 search.setQueryHint("search");方法。我访问searchview的EditText,并调用searchEditText.setHint("search here for quick access");

    【讨论】:

      【解决方案3】:

      试试这个来改变你的 searchView 提示颜色

      Style.xml

      <style name="SearchViewTheme" parent="Widget.AppCompat.Light.SearchView">
      <item name="android:maxWidth">10000dp</item>
      <item name="android:textColorHint">@android:color/white</item>
      

      搜索视图

      <android.support.v7.widget.SearchView
          android:id="@+id/search"
          style="@style/SearchViewStyle"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
         android:theme="@style/SearchViewTheme"
          android:clickable="true"
          android:focusable="true"/>
      

      或者,尝试通过 java 设置提示颜色:

      search = (SearchView) rootView.findViewById(R.id.search);
          searchEditText = (EditText)search.findViewById(android.support.v7.appcompat.R.id.search_src_text);
          searchEditText.setTextColor(getResources().getColor(R.color.colorPrimary));
          searchEditText.setHintTextColor(getResources().getColor(R.color.colorPrimary));
      

      【讨论】:

      • 你有工具栏吗,在你的activity.xml @MohdQasim中有它的默认或自定义工具栏
      • 这个也试了,没变。只是光标颜色会改变而不是提示文本颜色@abhishek kumar
      猜你喜欢
      • 2021-08-20
      • 2013-08-18
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多