自定义视图类位于活动之上

时间:2013-10-03 10:31:08

标签: android

我有一个Activity.There是原生的Java Unity视图。然后在它上面显示webview以显示HTML。因此,此活动将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);
}

我用过它。但它不起作用。帮我。

1 个答案:

答案 0 :(得分:0)

在Android中,您可以启动另一个活动:

    public void loadPrintActivity(String printUrl) {
        Intent intent = new Intent(this, Activity.class);
        startActivity(intent);
    }

从当前位于前台的Activity中。 Android然后维护一堆活动,如果用户按下“后退”按钮,他将返回到前面的活动。您可以对活动onResumeonPause中的所有内容做出反应。

有关详细信息,请查看Android的Guide about back stack