Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Styling the active SwitchAndroid color? #2903

Closed
danielkramer opened this issue Sep 21, 2015 · 16 comments
Closed

[Android] Styling the active SwitchAndroid color? #2903

danielkramer opened this issue Sep 21, 2015 · 16 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@danielkramer
Copy link

Is it possible to style the color of a SwitchAndroid? I can change the backgroundColor but not the active color

@ide ide added the Android label Sep 21, 2015
@ide ide changed the title SwitchAndroid color? [Android] Styling the active SwitchAndroid color? Sep 21, 2015
@kmagiera
Copy link
Contributor

We don't expose a way to customize it from JS at the moment. You can use custom android theme for your app and customize a way how switch should look there as you'd do in the native android app.

@nikolal
Copy link

nikolal commented Nov 3, 2016

Is there a plan to add onTintColor for Android in near future?

@sarovin
Copy link

sarovin commented Nov 22, 2016

+1

@nscoding
Copy link

Why is this issue closed? Aren't there any plans for this?

@otoinsa
Copy link

otoinsa commented Jan 12, 2017

That default teal color is not so great; is there still no way to customize it from react native without doing something in java?

@nikolal
Copy link

nikolal commented Jan 12, 2017

@otoinsa

I think this still isn't possible.

@otoinsa
Copy link

otoinsa commented Jan 27, 2017

So how would one exactly do this with a React Native android app?
I mean where/what code should I add, so that the switch is no longer teal/greenish colored?

For Example - I want the switch color to be blue, is there a comprehensive guide I can follow?

@otoinsa
Copy link

otoinsa commented Jan 30, 2017

I've managed to changed to whole app accent color, however is there a way to change just the switch accent color?

For me this does not work in styles.xml:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:switchStyle">@style/myswitch</item>
    </style>

    <style name="myswitch" parent="Theme.AppCompat.Light">
        <item name="colorAccent">#FF0000</item>
        <item name="colorControlActivated">#ff0000</item>
    </style>
</resources>

Only when I change the whole app accent color on theme editor, the switch changes.

@otoinsa
Copy link

otoinsa commented Jan 30, 2017

And this is still very much an issue, why is this closed?

@otoinsa
Copy link

otoinsa commented Jan 30, 2017

My styles.xml in android/res/values

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowIsTranslucent">true</item>
        <item name="colorControlActivated">#ffffff</item>
    </style>
</resources>

This in android native code will make all controls (checkboxes and radio buttons as well)
white; not perfect, but somewhat works for me.

@fabriziomoscon
Copy link

I solved this changing the XML in android/app/src/main/res/values/styles.xml like so

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowBackground">@color/darkBlue</item>
        <item name="colorPrimary">@color/darkBlue</item>
        <item name="colorPrimaryDark">@color/darkBlue</item>
        <item name="colorAccent">@color/brightBlue</item> <!-- this makes the trick -->
    </style>
</resources>

@Noitidart
Copy link

On Android, it's not possible to change the ripple color to match the thumb color. Isn't this correct?

Also is there ability to chagne size? I used transform scale but the layout of course doesn't respect that scaled size.

@MrLoh
Copy link

MrLoh commented Sep 19, 2017

Why is this issue closed? Clearly seems like something that should be possible.

@Noitidart
Copy link

@MrLoh we can change colors with onTintColor, thumbTintColor, tintColor. On Android, the ripple color cannot be changed, except for an app wide change via xml. On both iOS and Android, it is not possible to change size of Switch other then scale but this is not perfect, especially because it won't physically really take up that scaled size.

@thejacobseely
Copy link

@fabriziomoscon's solution worked for me.

However, keep in mind that changing the value of "colorAccent" will change the color accent default for your whole app, so you may have to go in and make some changes to the TextInput and other elements affected by the colorAccent.

It hasn't been mentioned all ready, so I figure I'll save anybody else who is using this solution some time:
You will also need to create a colors.xml file in the same directory, which should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="brightBlue">#00ffff</color>
</resources>

@jcurtis
Copy link
Contributor

jcurtis commented Feb 14, 2018

This appears to be solved with #11940

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests