2

这是我的代码:

public class SampleFB1Activity extends Activity {

WebView web2,childView =null;
private LinearLayout parentLayout;
private Activity MyActivity;
private String requestUrl="http://example.com/test.html";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.main);

    getWindow().setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_ON);
    parentLayout =(LinearLayout)findViewById(R.id.parentlayout);
    MyActivity = this;

    web2 = new WebView(this);
    web2.setLayoutParams(getLayoutParams());

    web2.setWebViewClient(new FaceBookClient());
    web2.setWebChromeClient(new MyChromeClient());
    web2.getSettings().setJavaScriptEnabled(true);
    web2.getSettings().setAppCacheEnabled(true);
    web2.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    web2.getSettings().setSupportMultipleWindows(true);
    web2.getSettings().setSupportZoom(true);
    web2.getSettings().setBuiltInZoomControls(true);

    parentLayout.addView(web2);
    web2.loadUrl(requestUrl);

}

private LayoutParams getLayoutParams() {
    // TODO Auto-generated method stub
    return new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); 
}

final class MyChromeClient extends WebChromeClient{
    @Override
    public boolean onCreateWindow(WebView view, boolean dialog,
            boolean userGesture, Message resultMsg) {
        childView = new WebView(SampleFB1Activity.this);
        childView.getSettings().setJavaScriptEnabled(true);
        childView.getSettings().setSupportZoom(true);
        childView.getSettings().setBuiltInZoomControls(true);
        childView.setWebViewClient(new FaceBookClient());
        childView.setWebChromeClient(this);
        childView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));

        parentLayout.addView(childView);

        childView.requestFocus();
        web2.setVisibility(View.GONE);

        WebView.WebViewTransport transport =(WebView.WebViewTransport)resultMsg.obj;
        transport.setWebView(childView);
        resultMsg.sendToTarget();
        return true;
    }

    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        MyActivity.setProgress(newProgress*100);
    }

    @Override
    public void onCloseWindow(WebView window) {
        parentLayout.removeViewAt(parentLayout.getChildCount()-1);
        childView =null;
        web2.setVisibility(View.VISIBLE);
        web2.requestFocus();
    }
}

    private class FaceBookClient extends WebViewClient{
     @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.i("REQUEST URL",url);
        return false;
    }   
}

    @Override
    public void onBackPressed() {
    if(childView != null && parentLayout.getChildCount()==2){
        childView.stopLoading();
        parentLayout.removeViewAt(parentLayout.getChildCount()-1);
        if(web2.getVisibility() == View.GONE)
            web2.setVisibility(View.VISIBLE);
    }else{          
        super.onBackPressed();
    }
}

在第 3 版中,我只能看到一半的评论框,在第 4 版中,它显示的是按钮(登录到 facebook 发表评论)而不是评论框,但不会显示评论框。请帮忙...

4

0 回答 0