Search Unity

Android: Input in Fragment invisible, but still interactable after update to Unity 5.6.1

Discussion in 'Android' started by LPeteR90, May 17, 2017.

  1. LPeteR90

    LPeteR90

    Joined:
    May 17, 2017
    Posts:
    4
    Hi,

    I am working on a custom Software Keyboard for Android, since the one coming with Unity didn't fit my company's requirements.

    It is basically implemented as a Fragment with an EditText (and some other components) as a View. Up until Unity 5.5 this was working great, but after we updated to 5.6.1, the Fragment View and all of its contained Views have become invisible. However, the views becoming invisible seems to be the only side effect. When clicking on the areas on the screen where the views should be, the Android OnClickListeners still get triggered and work as expected (the Logs are still correct).
    Oddly enough, when monitoring the Visibility in the Android Plugin, the Visibility of all Views in the Fragment is View.VISIBLE.

    We think this error might be related to following change in the changelog (https://unity3d.com/unity/whats-new/unity-5.6.1):
    -Android: SoftInput - Fixed input field hidden under keyboard when translucent flag was set.

    Does anybody maybe have a similar problem or any insights on that?

    #EDIT:
    I could provide a minimal Project where this behaviour is reproducable, please follow up if that would be required to further investigate. I would need to put in some time to cut it down to the important stuff.
     
    Last edited: May 19, 2017
  2. LPeteR90

    LPeteR90

    Joined:
    May 17, 2017
    Posts:
    4
    Ok, I found out what pretty sure is the cause of the behavior I've described.

    From 5.5 to 5.6 there have been some changes to the UnityPlayer.java class. One of them is the addition of a
    Code (JavaScript):
    1. this.m.setZOrderOnTop(true);
    call, with this.m being the Android SurfaceView Unity is drawing on. This causes the SurfaceView to be placed over the Android UI layer, thus my UI elements are not shown.

    If any Unity Dev reads this, was there a certain reason behind this change? Since the SurfaceView is a private member of the UnityPlayer.java class, I cannot imagine a sensible way to undo this setZOrderOnTop call. Finding a workaround for this does not seem very probable...
     
  3. LPeteR90

    LPeteR90

    Joined:
    May 17, 2017
    Posts:
    4
    Yup, just tried it out. I modified the classes.jar provided by Unity and removed the instruction from the bytecode, which led to the behavior I had before. So that was definitely causing the problem...

    This "workaround" doesn't seam feasible in the long run though...
     
  4. LPeteR90

    LPeteR90

    Joined:
    May 17, 2017
    Posts:
    4
    Ok, did some more research.

    According to https://fogbugz.unity3d.com/default.asp?902648_ds59pqgjtlmhhll9 , this is behavior by design. The recommended way of displaying android views is adding a second window (e.g. Popup Window, open a Dialog Window).

    Other ways (not recommended by Unity, but seem to be working) are:

    1. Override the UnityPlayerActivity and the UnityPlayer classes. In your new UnityPlayer implementation, override Views addView function, to call setZOrderOnTop(false) on any SurfaceViews before adding the View See following link for details: https://github.com/gree/unity-webvi...d/src/net/gree/unitywebview/CUnityPlayer.java

    2. According to a post in https://forum.unity3d.com/threads/u...n-cant-show-native-textview-or-layout.453193/ , you could programmatically get the Views attached to UnityPlayer. (UnityPlayer.currentActivity gives the UnityPlayerActivity) Then remove the SurfaceView attached to the rootView call setZOrderOnTop(false) on it and add it again to the rootView. Note however, that the person proposing this solution reported issues, so 1. would probably be a better solution.
     
  5. NicoL3AS

    NicoL3AS

    Joined:
    Oct 7, 2015
    Posts:
    18
    Hello @LPeteR90, I have the same problem here. Did you managed to get it work? It would be great if you can provide your altered "classes.jar" as a temporary solution, can you please?
     
  6. Hemaolle

    Hemaolle

    Joined:
    Jun 25, 2013
    Posts:
    10
    NicoL3AS likes this.