【问题标题】:How to change the color of the bottom line underneath a SearchView如何更改 SearchView 下方底线的颜色
【发布时间】:2019-07-05 10:08:03
【问题描述】:

非常简单,如何在 Android 中更改 SearchView 底部线条的颜色?我已经尝试过,queryBackground、background 和其他各种东西,但似乎无法在 XML 中得到它。我很高兴以编程方式或在 XML 中进行操作。只想让它工作!

干杯

【问题讨论】:

  • 你试过设置强调色吗?
  • @Shane Monks O'Byrne 已经尝试过我的回答。
  • 嗨 chetan ,我现在不在国内,我将在本周晚些时候尝试您的解决方案 - 非常感谢您的回答。如果正确,我会标记为答案!

标签: java android xml android-view searchview


【解决方案1】:

你好,试试这个可能对你有帮助

  android.support.v7.widget.SearchView searchView=findViewById(R.id.search_view);
    View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    v.setBackgroundColor(Color.parseColor("color code"));

【讨论】:

    【解决方案2】:

    使用Below方法改变SearchView底线的颜色。

    我在这里添加蓝色作为底线

    private void customizeSearchView() {
            int searchTextId = getResources().getIdentifier("android:id/search_src_text", null, null);
            EditText searchBox = ((EditText) searchView.findViewById(searchTextId));
            searchBox.setBackgroundColor(Color.WHITE);
            searchBox.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
            int search_plateId = getResources().getIdentifier("android:id/search_plate", null, null);
            View mSearchPlate = ((View) searchView.findViewById(search_plateId));
            mSearchPlate.setBackgroundColor(Color.BLUE);
    
            int searchCloseImageId = getResources().getIdentifier("android:id/search_close_btn", null, null);
            ImageView searchClose = ((ImageView) searchView.findViewById(searchCloseImageId));// change color
            searchClose.setBackgroundColor(Color.WHITE);
        }
    

    【讨论】:

    • 这就是答案,谢谢。值得注意的是,您还需要用背景颜色填充 EditText(就像您在这里一样),否则整个搜索视图都会改变搜索板的颜色。
    【解决方案3】:
    androidx.appcompat.widget.SearchView searchView = findViewById(R.id.Search_Categorie);
    View v = searchView.findViewById(androidx.appcompat.R.id.search_plate);
    v.setBackgroundColor(Color.parseColor("#ffffff"));
    

    【讨论】:

      猜你喜欢
      • 2017-02-07
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多