Search Unity

Any nice way to override @style/UnityThemeSelector styles?

Discussion in 'Android' started by jason_yak, Jul 1, 2017.

  1. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Hi there,

    I was wondering if anyone knows of a nice way to override the theme/styles when using @StyLe/UnityThemeSelector without needing to export an Android Studio Project ie. I have a build process that goes directly to apk. I also want to avoid a setup that requires having to manually edit the template style files inside of /Applications/Unity/PlaybackEngines/AndroidPlayer/Apk/ because the modifications are too easily forgotten, the changes would be lost when updating Unity and would not cover compiling across multiple machines.

    So far the only way I've been able to find is to copy the three folders values / value-v14 / values-21 and paste these in to Assets/Plugins/Android/res/.. then edit the style files, and also rename the styles and selector to something like @StyLe/CustomThemeSelector. But when I do this the assets get added into the project in a pretty ugly way, I changed the project to export an Android Studio Project simply to debug the output but in my setup its not a usable option, but anyway it shows that the three styles.xml files are being embedded under a strange unity-asset-resources bundle rather than overriding the original styles.xml files. I'd expected they would be overridden much like AndroidManifest.xml is if you provide your own custom file. Also when I add the custom styles.xml files to a res folder it gives me this warning: OBSOLETE - Providing Android resources in Assets/Plugins/Android/res is deprecated. So while it works now it probably won't some time soon.

    Any suggestions how I could do this and keep my compile process going straight to an APK file? does anyone know of a way to manipulate the staging files before they are actually compiled perhaps?

    Thanks all,

    Jason
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Can you describe what you're trying to achieve?
    What do you mean by "get added in a pretty ugly way" ?

    The only way to do this, is by including your own style. This can be done as you described by copying off the 3 folders under res/ from the Unity installation folder (that is, if you want to base yourself on Unity's "ThemeSelector" style).

    Once you copy these under Assets/Plugins/res you should rename them and also use your own style in the AndroidManifest.
     
  3. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    the ugly thing doesn't matter really.. it's more that when I use the described technique I get a warning that's it's obsolete ie. prompted that I shouldn't be doing it that way and just put it out there if someone knew of a cleaner alternative.
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Well, resources are provided as part of an .aar (or an "android library"). It used to also work when you include resources directly under Assets/Plugins/Android/res but they advise that this is deprecated and that you should include a library instead.
     
  5. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Ahh, ok right, of course! Should have been obvious, thanks!
     
  6. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Thanks that worked well. I've got a nice and tidy aar library that bundles the styles, and when compiled integrates cleanly.
     
  7. DavidLTP

    DavidLTP

    Joined:
    Dec 2, 2020
    Posts:
    6

    Sorry, could you give an explanation about how to do that? I've been trying to change icons color of status bar to dark, since they always appear on white, but there is no way to do that. Unity doesn't answer to any of these questions on the forum. I just want to change the icons color from white, to dark, and I guess that to do that I would have to change the styles.xml file.