我有一个 Activity。有原生 java Unity 视图。然后在它上面的 webview 来显示 HTML。所以这个 Activity 有 Unity 和 HTML 视图堆叠在一起。以下是活动:
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mUnityPlayer = new UnityPlayer(this);
context = this;
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
playerView.requestFocus();
mJSInterface = new JSInterface();
Log.e("Cookie", "COOKIE SUPPORT!");
mWebView = new WebView(this);
FrameLayout layout = new FrameLayout(this);
addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
layout.addView(mWebView, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY));
// Basic settings of WebView.
mWebView.setBackgroundColor(Color.TRANSPARENT);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSupportZoom(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){});
/* mJSInterface = new JSInterface();
mWebView.addJavascriptInterface(mJSInterface, "UnityInterface");*/
mWebView.addJavascriptInterface(mJSInterface, "UnityInterface");
// Start in invisible state.
mWebView.setVisibility(View.GONE);
}
我也有一个自定义视图类。我想在这个活动之上设置这个类。这是我的视图类:
public class PrintView extends LinearLayout {
WebView wv;
public PrintView(Context context) {
super(context);
// TODO Auto-generated constructor stub
View.inflate(context, R.layout.printscreen, this);
wv = (WebView) findViewById(R.id.webViewPrint);
wv.loadUrl(Constant.printUrl);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
for(int i = 0 ; i < getChildCount() ; i++){
getChildAt(i).layout(l, t, r, b);
}
}
}
在我的活动中有一个方法“loadPrintActivity”。当调用此方法时,我想要 Activity 顶部的视图类。这是方法:
public void loadPrintActivity(String printUrl) {
PrintView pv = new PrintView(context);
setContentView(pv);
}
我用过。但它不起作用。帮我。