'How to change the textColor for all widgets in the App when the theme is Material3

I want to change the default textColor of all text in my App. e.g. for all buttons, textViews, EditText's etc. in my App. Before moving to Material3, this was done using:

themes.xml

<style name="MyThemeName" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textColor">@color/black</item>

Now it doesn't work anymore. How do I do it now? The project is a default Android project:

<style name="Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
    <!-- This is not working -->
    <item name="android:textColor">@color/black</item>

    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/purple_200</item>
    <item name="colorPrimaryVariant">@color/purple_700</item>
    <item name="colorOnPrimary">@color/black</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_200</item>
    <item name="colorOnSecondary">@color/black</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
</style>

I can do it like this, but that is not the answer I'm looking for:

<style name="BaseStyle" parent="android:Widget.Material.Light.Button.Borderless"/>

<style name="Widget.Button.MyCompanyName" parent="BaseStyle">
    <item name="android:textColor">@android:color/black</item>
</style>

The above button style I only define the textColor when it differs from the default color that I want.



Solution 1:[1]

Does the below work? Not sure textViewStyle covers ALL texts. You might need some extra things like <item name="materialButtonStyle"> too.

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="android:textViewStyle">@style/MyTextView</item>
</style>

<style name="MyTextView" parent="Widget.MaterialComponents.TextView">
    <item name="android:textColor">@android:color/black</item>
</style>


Solution 2:[2]

The text color of the elements will change based on what type of element it is being shown on. for example if you are using the material button by default the button color will be "colorPrimary" and the button text color will be "colorOnPrimary". and similar to this if an element color uses the "colorBackground" its text color will be "colorOnBackground".

in my case i was able to control the text color of all the elements i use by adding a value for the following styles:

<item name="colorOnPrimary">#000000</item>
<item name="colorOnPrimaryContainer">#000000</item>
<item name="colorOnSecondary">#000000</item>
<item name="colorOnSecondaryContainer">#000000</item>
<item name="colorOnBackground">#000000</item>
<item name="colorOnSurface">#000000</item>
<item name="colorOnSurfaceVariant">#000000</item>
<item name="android:textColorPrimary">#000000</item>
<item name="titleTextColor">#000000</item>

you can read more about this in "Typography and iconography colors" section Here

Solution 3:[3]

With tracking you are usually left out with two approaches :

  • Either you ask your developer to implement a dataLayer event on a specific action / interaction so that you can then use this as a "custom event" trigger in GTM. For instance, here, on the login success page, after the GTM snippet, the developer could invoke the following code:

dataLayer.push({ event: 'login' })

That will allow you to use 'login' as your event name in GTM custom event trigger.

  • As you began doing, if your developer cannot implement it, you may try to identify variables that will help you isolate that specific action / page. For instance here, maybe does your successful login page has a specific URL you could use in a page view event, targeting that specific page path.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anders Ullnæss
Solution 2 Bilal Awwad
Solution 3 lkostka