material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[MaterialToolbar] SearchView text/hint not using colorOnPrimary

Open pamtbaau opened this issue 4 years ago • 4 comments

Description: When having the following layout defining the toolbar:

<com.google.android.material.appbar.MaterialToolbar
  ...
  style="?attr/toolbarStyle" 
/>

The colors of the Toolbar (title, subtitle, icons, ...) are set correctly to ?attr/colorOnPrimary. However, the text and hint of the SearchView are not.

Expected behavior: I would expect the colors of the SearchView to be the same as the tile/subtitle of the Toolbar.

Source code: The definition of ThemeOverlay.MaterialComponents.Toolbar.Primary is missing the color settings for the SearchView:

<style name="ThemeOverlay.MaterialComponents.Toolbar.Primary" parent="">
    <item name="colorControlNormal">?attr/colorOnPrimary</item>
    <item name="actionMenuTextColor">?attr/colorOnPrimary</item>
 </style>

When overriding the default ThemeOverlay with the following, it works fine:

<style name="ThemeOverlay.AppTheme.Toolbar.Primary" 
                parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
   <item name="android:editTextColor">?attr/colorOnPrimary</item>
   <item name="android:textColorHint">?attr/colorOnPrimary</item>
</style>

Android API version: 29

Material Library version: com.google.android.material:material:1.1.0

Device:

  • Emulator
  • Nokia 1

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

pamtbaau avatar Jun 09 '20 11:06 pamtbaau

You also need to override text cursor color by setting colorControlActivated:

<style name="ThemeOverlay.AppTheme.Toolbar.Primary" 
                parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
   <!-- other attributes -->
   <item name="colorControlActivated">?attr/colorOnPrimary</item>
</style>

vlad-kasprov avatar Aug 12 '20 12:08 vlad-kasprov

@VladyslavKasprov Thanks. Tried to lookup what the purpose is of item 'colorControlActivated' but have no idea yet... In my case, all is well with the changes I suggested.

pamtbaau avatar Aug 12 '20 14:08 pamtbaau

The SearchView should expose the hintTextAppearance and the textAppearance to style the component as I wish instead of having to find mSearchSrcTextView = findViewById(R.id.search_src_text).

sabinebarrera avatar Jan 15 '21 21:01 sabinebarrera

Dan, can you help confirm if the color settings are correct with M3 themes/styles?

drchen avatar Jul 08 '22 20:07 drchen