Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – Change Text color of Searchview implemented in OptionsMenu

Posted on November 14, 2022

Solution 1 :

You can’t change it from OptionsMenu. Instead, you can try programmatically using below code:

Kotlin with AndroidX:

 val searchView: SearchView = item.getActionView();
    val editText = searchView.findViewById<EditText>(androidx.appcompat.R.id.search_src_text)
    editText.setTextColor(getResources().getColor(R.color.white));
    editText.setHintTextColor(getResources().getColor(R.color.white));

Java with AndroidX:

SearchView searchView = (SearchView) item.getActionView();
    EditText editText = (EditText) searchView.findViewById(androidx.appcompat.R.id.search_src_text);
    editText.setTextColor(getResources().getColor(R.color.white));
    editText.setHintTextColor(getResources().getColor(R.color.white));

Solution 2 :

In the parent theme add the following:

  1. In the parent theme add the following:

<item name="android:editTextColor">@android:color/darker_gray</item>

Note that you can replace “@android:color/darker_gray” with your desired color.

For changing the hint you can use this:

android:queryHint="my_hint_here"

follow this link for more details

Solution 3 :

Below code worked for me:

  @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu,inflater);
        MenuItem item = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) item.getActionView();
        EditText editText = (EditText) searchView.findViewById(androidx.appcompat.R.id.search_src_text);
        editText.setTextColor(Color.WHITE);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItem.SHOW_AS_ACTION_IF_ROOM);
        item.setActionView(searchView);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }
            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
        searchView.setOnClickListener(new View.OnClickListener() {
                                          @Override
                                          public void onClick(View v) {

                                          }
                                      }
        );

    }

Solution 4 :

Add a custom theme to your Toolbar.

Something like this

<androidx.appcompat.widget.Toolbar
        android_id="@+id/toolbarMenu"
        android_layout_width="match_parent"
        android_layout_height="wrap_content"
        android_theme="?ref_toolbar_icon_tint"
        app_popupTheme="?ref_toolbar_popup_menu">

Then in your styles.xml add the following

<style name="toolbar_icons_theme_dark" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorControlNormal">--color of the icons--</item>
    <item name="android:editTextColor">--text color--</item>
    <item name="android:textColorHint">--hint color--</item>
</style>

and just call this custom style into your parent theme

    <item name="ref_toolbar_icon_tint">@style/toolbar_icons_theme_dark</item>

Problem :

I implemented a search view in options menu by using the following menu code.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns_android="http://schemas.android.com/apk/res/android"
    xmlns_app="http://schemas.android.com/apk/res-auto">
    <item
        android_id="@+id/search_toolBar"
        android_title="Search"
        android_icon="@drawable/search_icon"
        app_showAsAction="always|collapseActionView"
        app_actionViewClass="androidx.appcompat.widget.SearchView"
        />
</menu>

How to change the color of text of my search view. I want to also change the hint of searchview.

READ  [ANSWERED] android - Hilt java.lang.Integer cannot be provided without @inject constructor or @Provides - annotated method
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress