How can I change the action bar search view hint text colour?
This question explains how to get the EditText when using ABS: Android ActionBar Customize Search View
searchView.setQueryHint(Html.fromHtml("<font color = #ffffff>" + getResources().getString(R.string.hintSearchMess) + "</font>"));
Also you can set the SearchView on your menuItem manually and thereby have full control over the view.
I resolved it adding this property to the main theme:
<style name="AppTheme" parent="AppBaseTheme">
.....
.....
<item name="android:actionBarWidgetTheme">@style/MyActionBarWidgetTheme</item>
</style>
And then add the property i want to change in this case the hint color.
<style name="MyActionBarWidgetTheme" parent="@android:style/Theme.Holo">
.....
.....
<item name="android:textColorHint">@color/blanco_60</item>
</style>
Hope it helps :D
If you want to change left arrow button in search view, add app:collapseIcon.
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:collapseIcon="@drawable/ic_search_view_home"
/>
If you want to change text color and text hint color, add the following.
EditText searchEditText = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchEditText.setTextColor(Color.WHITE);
searchEditText.setHintTextColor(Color.WHITE);
If you want to change close icon, add the following.
ImageView imvClose = searchView.findViewById(android.support.v7.appcompat.R.id
.search_close_btn);
imvClose.setImageResource(R.drawable.ic_search_view_close);
Look to this class, it can help you to solve your problem
import android.R.color;
import android.content.Context;
import android.graphics.Typeface;
import android.widget.ImageView;
import com.actionbarsherlock.widget.SearchView;
import com.actionbarsherlock.widget.SearchView.SearchAutoComplete;
public class MySearchView {
public static SearchView getSearchView(Context context, String strHint) {
SearchView searchView = new SearchView(context);
searchView.setQueryHint(strHint);
searchView.setFocusable(true);
searchView.setFocusableInTouchMode(true);
searchView.requestFocus();
searchView.requestFocusFromTouch();
ImageView searchBtn = (ImageView) searchView.findViewById(R.id.abs__search_button);
searchBtn.setImageResource(R.drawable.ic_menu_search);
// ImageView searchBtnClose = (ImageView) searchView.findViewById(R.id.abs__search_close_btn);
// searchBtnClose.setImageResource(R.drawable.ic_cancel_search_bar);
SearchAutoComplete searchText = (SearchAutoComplete) searchView.findViewById(R.id.abs__search_src_text);
setFont(context, searchText);
searchText.setTextColor(context.getResources().getColor(color.white));
searchText.setHintTextColor(context.getResources().getColor(color.white));
return searchView;
}
private static void setFont(Context _context, SearchAutoComplete searchText) {
Typeface tf = null;
Typeface currentType = searchText.getTypeface();
if (currentType == null) {
tf = MyApplication.fontNormal;
}
else {
int currentStyle = currentType.getStyle();
if (currentStyle == Typeface.BOLD) {
tf = MyApplication.fontBold;
}
else if (currentStyle == Typeface.BOLD_ITALIC) {
tf = MyApplication.fontBoldItalic;
}
else if (currentStyle == Typeface.ITALIC) {
tf = MyApplication.fontItalic;
}
else {
tf = MyApplication.fontNormal;
}
}
searchText.setTypeface(tf);
}
public static SearchView getSearchView(Context context, int strHintRes) {
return getSearchView(context, context.getString(strHintRes));
}
}
The solution to change color of Search View Hint Text is :
SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchAutoComplete.setHintTextColor(Color.GRAY);