Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Feature Request Still not able to to change the background color of a Button

Discussion in 'UIElements' started by aybe, Dec 18, 2018.

  1. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    104
    I am looking for tinting a button like the following below:

    chrome_2018-12-18_07-08-53.png

    But unityBackgroundImageTint does absolutely nothing.

    Thanks !
     
  2. tea42

    tea42

    Joined:
    Jul 10, 2013
    Posts:
    18
    I'm pretty new to this, but you could try applying a style sheet (or perhaps a style directly to the element - I haven't tried that yet). For the gradient, you could maybe add a gradient image to it (black to white with some transparency so you can change colour easily on hover/disable etc).

    In uss file :

    Button
    {
    background-image: none; /* or a gradient: resource("your-gradient-image"); */
    background-color: rgb(56,200,86);
    color: #ffffff;
    }
     
  3. MartinIsla

    MartinIsla

    Joined:
    Sep 18, 2013
    Posts:
    64
    If you're not using the Experimental -and it's officially recommended not to use it- namespace (for some reason I couldn't do it when using Experimental), you can change the styles of the Unity buttons by overriding the .unity-button class in a USS file.

    I've done this:

    Code (CSharp):
    1. .unity-button {
    2.     background-color: rgb(60,60,60);
    3.     background-image: none;
    4.     color: rgb(230, 230, 230);
    5.     -unity-text-align:middle-center;
    6.     aasfjakl:4;
    7. }
    8.  
    9. .unity-button:hover {
    10.     background-color: rgb(230, 230, 230);
    11.     color: rgb(60,60,60);
    12. }
    13.  
    14. .unity-button:hover:active {
    15.     background-image: none;
    16.     background-color: rgb(130, 130, 130);
    17. }
    .unity-button is the button with no interactions
    The :hover pseudostate is the style when the mouse is over the button
    The :hover:active pseudostate is the style when the mouse is clicked.

    Cheers!

    EDIT: Just shared a gif about this on Twitter https://twitter.com/MartinRookbird/status/1075379826142384129
     
    Last edited: Dec 19, 2018
  4. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    104
    I am going to wait for an official fix (if ever :)) as I really don't feel generating all the states images for a correct render.

    In the mean time, good old GUI with IMGUIContainer just works:

    2018-12-19_18-50-35.png Unity_2018-12-19_18-50-24.png

    Thanks anyway !
     
  5. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    105
    Hello, which Unity version are using? Using the latest 2019.1 alpha the following UXML:

    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <UXML xmlns="UnityEngine.UIElements">
    3.    <Button text="Hello World!" style="-unity-background-image-tint-color: #F00" />
    4. </UXML>
    seems to give a correct result:



    Please report a bug if you believe there is an issue, if possible with a reproduction project.
     

    Attached Files:

  6. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    104
    Well, it's not working unfortunately.

    1. I could have never known I was missing the -color suffix, there are no docs talking about it at all and as you see below we can't read the full property name
    2. The property indeed is set but has no effect, see below
    3. Bug report sent: https://fogbugz.unity3d.com/default.asp?1111254_4a1ai4aco147a4bo
    2018-12-19_23-29-19.png

    2018-12-19_23-35-40.png
     
  7. uMathieu

    uMathieu

    Unity Technologies

    Joined:
    Jun 6, 2017
    Posts:
    48
    tint-color.png

    Hi Aybe,

    this bug was fixed in 2019.1.0a12 :
    tint-color.png

    Let us know if you get any trouble with other features
     
  8. aybe

    aybe

    Joined:
    May 24, 2015
    Posts:
    104
    Yes I confirm it works now, thanks :)