material-components-android
material-components-android copied to clipboard
[MaterialToolbar] SearchView text/hint not using colorOnPrimary
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.
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>
@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.
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).
Dan, can you help confirm if the color settings are correct with M3 themes/styles?