代码之家  ›  专栏  ›  技术社区  ›  Shane Monks O'Byrne

如何更改搜索视图下底线的颜色

  •  1
  • Shane Monks O'Byrne  · 技术社区  · 6 年前

    非常直接,如何在Android中更改搜索视图底部的线条颜色?我已经尝试过,查询背景、背景和其他各种东西,但似乎无法在XML中获得它。我很乐意以编程方式或XML方式进行。只想让它发挥作用!

    干杯 SearchView example

    2 回复  |  直到 6 年前
        1
  •  1
  •   Chetan Joshi weird    6 年前

    使用下面的方法更改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);
        }
    
        2
  •  0
  •   Muhammad Haroon    6 年前

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

      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"));