Can the user change colors of the already compiled application?

Asked

Viewed 55 times

0

I’m thinking about creating an app where the user can change their Layout colors as they wish with predefined colors, but I can’t think of a way to do that, if that’s possible. Someone has something like?

  • Be more specific. Want to change the color of what exactly? Do you have a screen with a specific component that needs to change color? If yes, put her code here (and XML).

  • You must be looking to change XML data at runtime. I think this topic should help you: https://answall.com/questions/160924/alterar-programmation_cor-de-fundo-do-menu-overflow-na-toolbar Take a look and tell me if that’s right.

  • I want to change the colors of the statatus bar and the drawables that are being used to style buttons, as an example of the Twitter app, has two themes, one leaves the entire app light and the other dark.

1 answer

1


I found an easy way.

I created a res/values/attrs.xml file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="drawable_color" format="reference" />
    <attr name="background_color" format="reference"/>
    <attr name="font_color_1" format="reference" />
    <attr name="font_color_2" format="reference" />
</resources>

And in the res/values/Styles.xml file I added the following code:

<style name="RedTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorDkRed2</item>
    <item name="colorPrimaryDark">@color/colorDkRed1</item>
    <item name="colorAccent">@color/colorBlack1</item>
    <item name="drawable_color">@color/colorDkRed2</item>
</style>

Where I can set the color you want for this attribute that will be applied to the drawable item.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.