Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CookieSteve · Mar 01, 2019 at 01:58 AM · uidropdownlistenercoloureventlistener

How can I change the colour of Dropdown List items in runtime?

I need to be able to change the colour of individual dropdown list items. I've noticed that this can be done in the editor by directly modifying the value of the item's colours while the dropdown list is open:

alt text

However, this only works for as long as the dropdown list is open. If you close and re-open the list, the colours will reset to default. Furthermore, since my dropdown lists are created during runtime, they need to have their colours assigned during runtime too.

One way I thought I could accomplish this would be to have a listener that would trigger whenever the dropdown list was selected, whereupon I could just find the relevant list items and change them that way. However, the only listener I could find that related to dropdowns is the 'OnValueChanged' one, which only triggers once one of the list items has been selected (by which point it's too late).

Is there any way to either add a listener to the dropdown list that activates whenever it's opened, or to just edit the colour of individual dropdown options upon creation? Any help would be appreciated!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by WarmedxMints · Mar 01, 2019 at 04:17 AM

The best way really would be to make your own dropdown. Fortunately, Unity is kind enough to share the UI code. You can find the dropdown code here link text

Use that to make your own dropdown class and modify the Show() method,

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CookieSteve · Mar 01, 2019 at 12:09 PM 0
Share

Ah, good to know! Thank you!

avatar image
1

Answer by donkey0t · Sep 21, 2020 at 11:21 AM

I extended the existing control rather than re-writing it. It's just a different approach. https://youtu.be/N0afV6h2L6o

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Number11 · Nov 05, 2020 at 11:35 AM

You can achieve this by simply adding a component to your template's item. Under the GameObject named 'Template', you wil find an GameObject named 'Item'. It is duplicated each time an item of the dropdown list is created.

You can add something like the code below to the 'Item' GameObject. In the editor, simply drop the Image component from the 'Item Background' GameObject to the field Image (or find it via code, depending on your needs).

Then, each time the template's item will be duplicated, the ColorChanger component will be created and started. This is just to give the idea, explore and customize to your needs ;) (here I did not do the filtering to show how to highlight a single item, but this should be easy)

 public class ColorChanger : MonoBehaviour
 {
     public Image image;
 
     // Start is called before the first frame update
     void Start()
     {
         image.color = Color.red;
     }    
  }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by yeshiazev · Oct 10, 2019 at 05:25 AM

I believe my solution will help. If I understand correctly, you want to set a background color for the selected item in the drop down? I don't have the code to set this all up, but this is how I did it through the Inspector.

Under Viewport-Content-Item: I use the "Item Checkmark" as a way to color the row. Set the Item Checkmark's Rect Transform to Strech both directions. Left/Right/Top?Bottom to 0 Set the Item Checkmark's Color to whatever color you like, then set the Alpha to allow the text to be seen through the Checkmark's color.

This should highlight the selected item using the Checkmark Item, which the DropDown sets for you. Hope this helps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Yleisnero · Oct 24, 2019 at 10:16 AM

As @WarmedxMints said, it's probably the best to make your own dropdown. I've created one, which fits my usage. Maybe it helps: https://github.com/Yleisnero/unitycolordropdown

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

172 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get a dropdown menu to change the colour of a reticule on another scene 0 Answers

Native Picker Wheel - iOS UI 0 Answers

Why UI event handlers dont get memory leaks if listener not removed 1 Answer

Does anyone know how to make a Dropdown inside an element of another Dropdown? 0 Answers

Making a blocker like dropdown menu for another gameobject. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges