簡體   English   中英

如何更改 SearchView 下底線的顏色

[英]How to change the color of the bottom line underneath a SearchView

非常簡單,如何在 Android 中更改 SearchView 底部線條的顏色? 我已經嘗試過,queryBackground、background 和其他各種東西,但似乎無法在 XML 中獲取它。 我很高興以編程方式或 XML 格式進行操作。 只是想讓它工作!

干杯搜索視圖示例

使用 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);
    }

嗨試試這個它可能會幫助你

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM