umi
umi copied to clipboard
How do you change Placeholder & Text color runtime?
I want to change my InputFields text runtime from Black or White. I've had weird bugs where the app slowed down with some of my questionable solutions. Below are solutions I used to try and make this work.
Adding this to the MobileInputField.cs
private void Update () {
if (PlayerPrefs.GetInt ("Theme") == 0) { // Light Theme
_config.PlaceholderColor = Color.black;
_config.TextColor = Color.black;
} else if (PlayerPrefs.GetInt ("Theme") == 1) { // Dark theme
_config.PlaceholderColor = Color.white;
_config.TextColor = Color.white;
}
}
I've tried re initializing the InputField (in an update) to hopefully change the color, but this failed. It did not like that :D
There doesn't seem to be a solid way to change the text color runtime, no arguments to pass, nothing.
This would be a great feature to add if viable, or any 'hacky' solution would work too.
In current realization you cannot do it in runtime. But you can add that methods in plugin and make PR.
I have no clue how to do any of that. :D
I'm just guessing at this based on using this script and messing around with what I have already, and from what I understand, please correct me if I'm wrong.
Would it be possible to create a method that changes the _config in the PrepareNativeEdit function but does a small update instead of preparing it again?
Or would we need to modify the data in the CreateNativeInput function and then just make a small update (not a new instialize, from what I know it doesn't like it when I do that). I'm not sure how easy it to just 'update' the input and have it work I don't know how that part works.
Is there a feasible way to dynamically update any of the variables I mentioned above?
No, to do it correctly, I have to add some native methods and implementation in Unity. I added this to my todo list.
I have the same problem, has it been solved?
Not as far as I know..
So,how did you end up settling it?
I didnt
me too
Maybe you could make it a prefab and intialize it with said color constantly?
This is not a good way,I think it should be modified from Android source.