Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 5.6.0b3 - Android plugin: can't show native TextView or Layout

Discussion in 'Android' started by BenoitFreslon, Jan 26, 2017.

  1. BenoitFreslon

    BenoitFreslon

    Joined:
    Jan 16, 2013
    Posts:
    163
    Hello i'm trying to add a simple TextView with an Android plugin.
    But I discovered that we can't add a new native view above the UnityPlayer.currentActivity

    UnityPlayer.currentActivity.addContentView > Shows the view in the background. So the native view is hidden.

    I can't set the new view on top, above the UnityPlayer.

    Code (JavaScript):
    1.     public static void addText2() {
    2.         UnityPlayer.currentActivity.runOnUiThread(new Runnable()
    3.         {
    4.             public void run()
    5.             {
    6.  
    7.                 TextView tView = new TextView(UnityPlayer.currentActivity.getApplicationContext());
    8.                 tView.setText("TextView Programmatically AddText 2.");
    9.                 tView.setTextSize(22);
    10.                 tView.setEnabled(true);
    11.                 tView.setTextIsSelectable(true);
    12.                 tView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    13.                 tView.setPadding(20, 0 , 20, 0);
    14.                 tView.setTextColor(Color.parseColor("#FF0000"));
    15.                 tView.setGravity(Gravity.CENTER);
    16.                 tView.bringToFront();
    17.  
    18.                 LinearLayout linearLayout = new LinearLayout(UnityPlayer.currentActivity.getApplicationContext());
    19.                 linearLayout.addView(tView);
    20.                 linearLayout.bringToFront();
    21.                 linearLayout.setGravity(Gravity.CENTER);
    22.                 linearLayout.setPadding(20 , 0, 20, 0);
    23.  
    24.                 UnityPlayer.currentActivity.addContentView(linearLayout, new LayoutParams( LayoutParams.FILL_PARENT , LayoutParams.FILL_PARENT ));
    25.             }
    26.         });
    27.     }
     
  2. shawnhunag

    shawnhunag

    Joined:
    Feb 6, 2013
    Posts:
    1
    my project also have this issue, please fix as soon as possible.this is a big bug.....why do i must take a huge risk of upgrading in Unity 5.x every time ......Unity 5.x in Android is very unsettled .......


    ps. when i use Unity 5.5, this issue will not happen.....so Unity 5.6 is suck.....
     
  3. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    174
    Last edited: Apr 18, 2017
  4. Oscar-Tsang

    Oscar-Tsang

    Joined:
    Nov 7, 2012
    Posts:
    84
    Same for me, using 5.6. Now it is unable to add Ad Banner, because the banner is show under the unity player. ie. Hidden.!

    Fullscreen ad it no problem.
     
  5. starstablesimon

    starstablesimon

    Joined:
    Nov 24, 2016
    Posts:
    18
    This guy solved it, and confirmed it works for my other plugin as well.

    https://github.com/gree/unity-webview

    "For Unity 5.6 or newer, you also need to modify android:name from com.unity3d.player.UnityPlayerActivity tonet.gree.unitywebview.CUnityPlayerActivity. This custom activity implementation will adjust Unity's SurfaceView z order."
     
  6. plasticYoda

    plasticYoda

    Joined:
    Aug 20, 2013
    Posts:
    62
    I was able to do something similar by adjusting the SufaceView child of com.unity3d.player.UnityPlayer, its not pretty, but it does work without having to mess with the manifest.

    unityPlayer.removeView(surfaceView);
    surfaceView.setZOrderOnTop(false);
    unityPlayer.addView(surfaceView);

    My code finds the unityPlayer ViewGroup, finds the SurfaceView child, removes it (screen goes black), modifies the ZOrder, and then adds it back. I then add my custom Views as normal.

    I've got more work & testing, then I'll post some code.

    Update: While the hack worked initially, the test app would quit after a varying amount of time, but not with a crash... at this point, I'm going to roll back to Unity 5.5.3
     
    Last edited: Apr 25, 2017
  7. Oscar-Tsang

    Oscar-Tsang

    Joined:
    Nov 7, 2012
    Posts:
    84
    Find Unity-Admob, they have fixed this problem by using popupwindows class. I think unity are not see it is a problem.
     
  8. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    174
    Yeah, seems like it. My issue already was answered.
     
  9. tyomklz

    tyomklz

    Joined:
    Jul 31, 2015
    Posts:
    48
    Bumb. Unity, please, fix it with upcoming patch :'(
     
  10. tteneder

    tteneder

    Unity Technologies

    Joined:
    Feb 22, 2011
    Posts:
    174
  11. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
  12. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
  13. zaniocz

    zaniocz

    Joined:
    May 9, 2011
    Posts:
    24
    Hi Voxel,

    Yes, this issue is already fixed in 5.6.1p4 (https://unity3d.com/unity/qa/patch-releases/5.6.1p4)
    - (916119) - Android: Fixed a regression where Banner Ads are invisible, but still clickable.
    You can try with this version to check if this works on your side.
     
  14. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
    Thanks for updating @zaniocz !
    I will give a try today.

    Also is this fix any way related to this issue and got resolved too?
     
  15. vourkosa

    vourkosa

    Joined:
    May 26, 2017
    Posts:
    2
    You can read more on what actually happened behind the scenes with this issue at the following article https://goo.gl/jMwQ21
     
  16. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
    @vourkosa Thanks for sharing! Interesting read!