0

The status bar, app bar icons, and alert dialog's positive and negative buttons all of these went from their default colors to purple after going into styles.xml and doing the following:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="shapeAppearanceMediumComponent">@style/AppShapeAppearance.MediumComponent</item>
</style>

I used to have Theme.AppCompat and I didn't have this purple color issue. How do I change the purple colors back to its default colors from AppCompat?

Tom Darious
  • 434
  • 6
  • 18
  • This is a bit of a strange question. There's no 'default' colour, the colours are determined by the theme, so what you're looking for is specifically the colours from `AppCompat`. The purple is the 'default' chosen by the material theme, it's not an "issue". – Henry Twist May 27 '21 at 01:11
  • Well, what are the colors for the `AppCompat` theme? I didn't include anything like `@color/colorPrimary` before so I'm not entirely sure what the colors are. – Tom Darious May 27 '21 at 01:18
  • There are plenty of resources on this, this question was the first search result and seems quite well answered: https://stackoverflow.com/questions/26583780/where-can-i-find-the-default-styles-for-theme-appcompat-light – Henry Twist May 27 '21 at 01:20
  • @HenryTwist This still doesn't address what I'm supposed to do with those colors and how to get back the original theme. – Tom Darious May 27 '21 at 01:24
  • If you want to go back to the `AppCompat` theme then surely you shouldn't be using the material one? And asking what to do with the colours is a massive question, it depends on what they're for, however the answer you've got provides a link to the official theming documentation which would be a good place to start. – Henry Twist May 27 '21 at 01:27
  • colors.xml should contain 3 values colorPrimary, colorPrimaryDark, colorAccent this is what AppCompact was using by default. Materials has 6 colors by default, refer to my answer to change the colors, you may not get the original 100% back automatically as its a completely different system. – avalerio May 27 '21 at 01:29
  • @HenryTwist I have to use the material theme to use `TextInputLayout` or else the app crashes. – Tom Darious May 27 '21 at 01:30
  • 1
    "I have to use the material theme TextInputLayout or else the app crashes" that is 100% wrong, the issue is cause by something else. – avalerio May 27 '21 at 01:32
  • Well as far as I'm aware, they haven't created an extension to the material theme that uses a different theme's colour palette, that wouldn't make much sense. – Henry Twist May 27 '21 at 01:32
  • @HenryTwist No, it's not wrong. Look at this answer: https://stackoverflow.com/a/56213981/14150504 – Tom Darious May 27 '21 at 01:35
  • You tagged me in your comment, but I didn't mention the crash. I think you meant to tag @avalerio. – Henry Twist May 27 '21 at 01:40
  • I am currently using `TextInputLayout` in production code, that is using `AppCompat` theme. You have to style `TextInputLayout` at the view level, meaning you can't theme it but you can still use it. If the coloring is a make it or break it for you that is your only option. Or you fine grain go through every single difference between the two theme sets and make them match. – avalerio May 27 '21 at 01:41
  • @avalerio I don't need to theme TextInputLayout, so how would I style it at the view level so I can just use `AppCompat`? – Tom Darious May 27 '21 at 01:53
  • I'll have to get back to you on that tomorrow as I dont have the xml handy at the moment. What is your minimum api as that matters what you have access to at the view level? – avalerio May 27 '21 at 02:04
  • @avalerio `minSdkVersion 21` – Tom Darious May 27 '21 at 02:08
  • `android:theme="@style/Widget.Design.TextInputLayout"` throw that in your `com.google.android.material.textfield.TextInputLayout` in your xml. Later on you can make a style that has `parent="Widget.Design.TextInputLayout"` and style it. Weirdly enough not including it at all didn't break the view, the only thing that broken the view was `android:theme="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"` – avalerio May 27 '21 at 11:59
  • @CodeShane No, you sent the same link that has already been addressed by the earlier comments. – Tom Darious May 27 '21 at 15:41
  • @TomDarious Okay, removed redundant link. – CodeShane Jun 08 '21 at 01:33

1 Answers1

3

Here is a link to the Materials webstite https://material.io/develop/android/theming/color

under "Using The Color Theming System" Those six values which you would add as item to your theme dictates the color palette, if you see the defualt colors to to the right you will see they are purple if you look up the numbers. AppCompat uses the Standard 3 colorPrimary, colorPrimaryDark, colorAccent. 2 of which are not used in MaterialComponents.

to get you started add these to your theme

<item name="colorPrimary">#5C9EAD</item>
<item name="colorPrimaryVarient">#326273</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorSecondary">#E39774</item>
<item name="colorSecondaryVariant">#E39774</item>
<item name="colorOnSecondary">#EEEEEE</item>
avalerio
  • 2,072
  • 1
  • 12
  • 11
  • Shouldn't those be `color` rather than `item` and placed in the `colors.xml` file? – Tom Darious May 27 '21 at 01:02
  • No, styles use the `item` tag like in the sample in your question. However it probably would be good practice to declare them as colour resources too. – Henry Twist May 27 '21 at 01:09
  • 1
    Yes of course use the color.xml, I thought that might have been too indepth seeing you didn't know why the colors changed.(Literally no offense it just seemed out of scope) You could even take it a step further and make references to allow the swapping of colors, allowing the addition of multiple themes with minimal effort. – avalerio May 27 '21 at 01:20