Search Unity

AddContentView to Unity's view somewhere turned black

Discussion in 'Android' started by ChanMOOOOR, Jun 27, 2014.

  1. ChanMOOOOR

    ChanMOOOOR

    Joined:
    May 7, 2014
    Posts:
    10
    I'm sorry for my poor English.After searching for some threads,it seems my situation is different.So i really need help ,i have no idea how to fix this.
    I'm going to insert a WebView to the Activity with below lines:

    Code (CSharp):
    1.  
    2.                 layout = new RelativeLayout(UnityPlayer.currentActivity.getApplicationContext());
    3.                 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
    4.                         RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
    5.                 //MainActivity.this.addContentView(layout, params);
    6.                 UnityPlayer.currentActivity.addContentView(layout, params);
    7.                 WebView web = new WebView(UnityPlayer.currentActivity.getApplicationContext());
    8.                 web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    9.                 web.getSettings().setUseWideViewPort(false);
    10.                 RelativeLayout.LayoutParams webparams = new RelativeLayout.LayoutParams(
    11.                         width,height);
    12.                 webparams.setMargins(leftMarginInt, bottomMarginInt, leftMarginInt, bottomMarginInt);
    13.                 layout.addView(web,webparams);
    14.          
    15.                 web.loadUrl(uri);
    16.                
    17.                 layout.postInvalidate();
    18.                 web.requestFocus();
    However,"Sometimes" it looks like some where out of the WebView turned black , just after touch the screen everything goes well .Is Android kidding me?
     

    Attached Files:

  2. ChanMOOOOR

    ChanMOOOOR

    Joined:
    May 7, 2014
    Posts:
    10
    OK,i'm still struggling .BUT , if i load the url which is sample enough(like google's home page),no more problem,everything goes well. so, if there is a way i can deal with the website will be one of the solutions.