I feel like I must be doing something really stupid. I can deploy the example UI project to my Windows Phone and the InputFields work fine (in the Widget scene).
But when I add my own (even in that same scene) they don’t. Tapping on them brings up the phones keyboard, but the actual text is not selected and it seems like the control doesn’t get focused. Typing does nothing.
The really weird thing is that 1 of every 10 or so taps actually works perfectly, but not the rest of the time.
I’ve tried constructing my input fields property-per-property exactly as the example ones, and they still don’t work.
I tried copying one of the two example InputFields to a different place on the scene and it seems like that has completely broken them all.
Any movements there? I have same problem with Unity 5.0 and I just updated to the 5.0f1 and still same problem with our Android build. Inputfield gets the focus but onscreen keyboard doesn’t show up. I have tried it with Nvidia shield tablet, Samsung galaxy tab 2 and with LG Nexus 5. Everything Works on pc. I also made one plain test scene only with three inputfields and eventmanager. It didn’t work.
My workaround was old gui input field wiht custom GUISkin.
“PasswordInput” variable is my uGui inputfield gameobject in the scene.
“password_default” is string variable with place holder text.
I used widthScaler and heightScaler floats because my orginal uGui is releative to screen size, so I can set dimensions of my input fields as percentages of screen size.
void OnGUI()
{
GUI.skin = skin;
int width = Mathf.RoundToInt(Screen.width / widthScaler);
int height = Mathf.RoundToInt(width / heightScaler);
GUI.skin.textField.fontSize = Mathf.RoundToInt(height / fontscaler);
if (passwordInput.gameObject.activeSelf)
{
Vector3 position = Camera.main.WorldToScreenPoint(passwordInput.transform.position);
GUI.SetNextControlName("password_field");
passugui = GUI.PasswordField(new Rect(Mathf.RoundToInt(position.x) - width / 2, Screen.height - Mathf.RoundToInt(position.y) - height / 2, width, height), passugui,'*');
if (UnityEngine.Event.current.type == EventType.Repaint)
{
if (GUI.GetNameOfFocusedControl() == "password_field")
{
if (passugui == password_default) passugui = "";
}
else
{
if (passugui == "") passugui = password_default;
}
}
}
}
I’ve come up with a quick and dirty fix. It checks to see if the text has disappeared and if so uses the last stored value: (This is a fix for the problem of text in the textfield disappearing after you type it)
string tempvalue="";
public void ValueChange(string s){
//Fix for Android: Prevent text disapearing after input
if((s=="" || s==null) && tempvalue.Length>1) {
s = tempvalue;
}
else tempvalue = s;
}
public void EndEdit(string s){
//fix for Android: If text has disapeared use last available:
if(s=="" && tempvalue!="") {
s = tempvalue;
inputfield.text = tempvalue;
}
//do something with value
text2.text = s;
}
It also prevents you from deleting all the text in a textfield in one go. But I think that’s a small price to pay.
Happy with that. Me-1 Unity-0
Unless anyone’s got a better solution they could share?