I am using search view.
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/imageViewMenu"
>
</android.support.v7.widget.SearchView>
Is this possible to change text color and icon color to view?
Currently it shows black text and icon. I want to change it to white color text and white search icon.
This may work..
SearchView searchView = (SearchView) findViewById(R.id.search);
EditText searchEditText = (EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchEditText.setTextColor(getResources().getColor(R.color.white));
searchEditText.setHintTextColor(getResources().getColor(R.color.white));
For the android.support.v7.widget.SearchView you can change the text color, text hint color and the icon with this code :
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem searchMenuItem = menu.findItem(R.id.menu_action_search);
SearchView searchViewAction = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
searchViewAction.setSearchableInfo(searchableInfo);
searchViewAction.setIconifiedByDefault(true);
EditText searchEditText = (EditText)searchViewAction.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchEditText.setTextColor(getResources().getColor(R.color.white));
searchEditText.setHintTextColor(getResources().getColor(R.color.white));
ImageView searchMagIcon = (ImageView)searchViewAction.findViewById(android.support.v7.appcompat.R.id.search_button);
searchMagIcon.setImageResource(R.drawable.ic_search_white);
return super.onPrepareOptionsMenu(menu);
}
To Change the Text color :
int searchSrcTextId = getResources().getIdentifier("android:id/search_src_text", null, null);
EditText searchEditText = (EditText) searchView.findViewById(searchSrcTextId);
searchEditText.setTextColor(Color.WHITE);
searchEditText.setHintTextColor(Color.LTGRAY);
To Change the close button :
int closeButtonId = getResources().getIdentifier("android:id/search_close_btn", null, null);
ImageView closeButtonImage = (ImageView) searchView.findViewById(closeButtonId);
closeButtonImage.setImageResource(R.drawable.ic_action_cancel);
// This excerpt is from Android source code (SearchView.java)
mSearchButton = findViewById(R.id.search_button);
mSearchEditFrame = findViewById(R.id.search_edit_frame);
mSearchPlate = findViewById(R.id.search_plate);
mSubmitArea = findViewById(R.id.submit_area);
mSubmitButton = findViewById(R.id.search_go_btn);
mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
mVoiceButton = findViewById(R.id.search_voice_btn);
mSearchHintIcon = (ImageView) findViewById(R.id.search_mag_icon);
Reference : link
If it resides in toolbar, set theme for toolbar. For example this makes the text(and icon) white
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >
<item name="colorControlHighlight">@color/LightGray</item>
<item name="android:textColorHint">@color/LightGray</item>
<item name="android:editTextColor">@color/TransparentGray</item>
</style>
apply this theme to your toolbar hint that (colorControlHighlight) color of ripple effct of your menu items
Yes, you can do it, one of ways to do it:
public static void customizeSearchView(SearchView searchView) {
int searchTextViewId = searchView.getContext().getResources()
.getIdentifier("android:id/search_src_text", null, null);
AutoCompleteTextView searchTextView
= (AutoCompleteTextView) searchView.findViewById(searchTextViewId);
searchTextView.setTextSize(14);
searchTextView.setTextColor(Color.WHITE);
}