umi icon indicating copy to clipboard operation
umi copied to clipboard

How do you change Placeholder & Text color runtime?

Open Jared-Gross opened this issue 4 years ago • 10 comments
trafficstars

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.

Jared-Gross avatar Jan 21 '21 05:01 Jared-Gross

In current realization you cannot do it in runtime. But you can add that methods in plugin and make PR.

mopsicus avatar Jan 21 '21 07:01 mopsicus

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?

Jared-Gross avatar Jan 22 '21 15:01 Jared-Gross

No, to do it correctly, I have to add some native methods and implementation in Unity. I added this to my todo list.

mopsicus avatar Jan 24 '21 19:01 mopsicus

I have the same problem, has it been solved?

luodiyanhua avatar Jun 23 '22 03:06 luodiyanhua

Not as far as I know..

Jared-Gross avatar Jun 24 '22 00:06 Jared-Gross

So,how did you end up settling it?

luodiyanhua avatar Jun 27 '22 07:06 luodiyanhua

I didnt

Jared-Gross avatar Jul 01 '22 04:07 Jared-Gross

me too

luodiyanhua avatar Jul 01 '22 06:07 luodiyanhua

Maybe you could make it a prefab and intialize it with said color constantly?

Jared-Gross avatar Jul 01 '22 13:07 Jared-Gross

This is not a good way,I think it should be modified from Android source.

luodiyanhua avatar Jul 04 '22 09:07 luodiyanhua