SandeepM
SandeepM

Reputation: 2609

Change SearchView Text Color Xamarin.Android

I want to change the search text view color in Xamarin.Android. I have tried below code so far

        searchView = this.Activity.FindViewById<Android.Support.V7.Widget.SearchView (Resource.Id.searchView);
        searchView.SetOnQueryTextListener(this);
        var textViewId = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
        var textView = (searchView.FindViewById(textViewId) as TextView);
        if (textView != null)
            textView.SetTextColor(global::Android.Graphics.Color.White);

I am getting NULL when I try to capture the textView

In textViewId I'm getting the id of the view something like 126312727

Can anyone help me on above?

Upvotes: 4

Views: 707

Answers (2)

Jonty
Jonty

Reputation: 672

I needed to use the below with AppCompat and CrossCurrentActivity plugin.

var searchEditText = (CrossCurrentActivity.Current?.Activity as MainActivity)?.FindViewById<AutoCompleteTextView>(Resource.Id.search_src_text);
searchEditText.SetTextColor(Color.Red);

Upvotes: 0

SushiHangover
SushiHangover

Reputation: 74144

This is right out of app using Android.Support.V7.Widget.SearchView

var id = searchView.Context.Resources.GetIdentifier("search_src_text", "id", PackageName);
var searchEditText = searchView.FindViewById<EditText>(id);
searchEditText.SetTextColor(Color.Red);

Upvotes: 2

Related Questions