5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Themeを使わずにAppCompt SearchViewのカスタマイゼーション

Last updated at Posted at 2016-06-15

いろんな原因でthemeの使用を諦めてコードでAppcomptのSearxchViewをカスタマイズしたいです。一番詰んだのはSearchIconの削除です。ソースコードは下記の通りです。ご参考になれれば幸いです。

要注意のは```
searchView.setIconifiedByDefault(false);


コード

SearchView searchView = (SearchView)findViewById(.....);
// hint text color
((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setHintTextColor(.....);
// query text color
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).setTextColor(.....);
// remove search view underbar
searchView.findViewById(android.support.v7.appcompat.R.id.search_plate).setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
// set close button image
((ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn)).setImageResource(.....);
// remove search icon
searchView.setIconifiedByDefault(false);
ImageView image = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
image.setAdjustViewBounds(true);
image.setMaxWidth(0);
image.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
image.setImageDrawable(null);
// set query hint sting
searchView.setQueryHint(.....);


間違ったところがあったらご指摘いただけると幸いです。
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?