如何在SearchView中删除search_plate

时间:2014-12-29 10:28:09

标签: android searchview

enter image description here

我可以使用以下代码更改SearchView的背景:

    mSearchView = (SearchView) findViewById(R.id.search_search_view);
    LinearLayout layout = (LinearLayout)mSearchView.findViewById(mSearchView.getContext().getResources().getIdentifier("android:id/search_bar", null, null));
    layout.setBackground(getResources().getDrawable(R.drawable.curve_stroke_border_white_bg));

但如何在搜索视图中删除search_plate在图片中选择的红色显示)。

任何人都有任何想法请帮助我..

谢谢你。

2 个答案:

答案 0 :(得分:3)

假设,这会对你有所帮助

int searchPlateId = searchView.getContext().getResources()
        .getIdentifier("android:id/search_plate", null, null);
View searchPlateView = searchView.findViewById(searchPlateId);
if (searchPlateView != null) {
    searchPlateView.setBackgroundColor(Color.BLACK); //depand you can set
}

答案 1 :(得分:1)

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        getMenuInflater().inflate(R.menu.home, menu);

        MenuItem searchMenuItem = menu.findItem(R.id.activity_home_action_search); 
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

        View searchplate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
        searchplate.setBackgroundResource(android.R.color.transparent);
}