簡體   English   中英

Webview內部彈出窗口android

[英]Webview Inside popup window android

在此處輸入圖片說明

嗨,我有一個問題,如上圖所示,在左側的webview中有一個按鈕。 當我單擊按鈕時,應該會出現android中的popupwindow。 在該彈出窗口中,我需要一個webview。 現在,沒有彈出窗口中的webview,一切正常。

此彈出窗口由javascript界面​​調用

public class AppJavaScriptProxy {

    private Activity activity = null;

    public AppJavaScriptProxy() {

    }

    @JavascriptInterface
    public String showMessage(String footNoteNo) {
        Integer footNoteNoInt = Integer.parseInt(footNoteNo);
        footnote = myDbHelper.getFootnote(chapterNumber, footNoteNoInt);

        try {

            LayoutInflater inflater = (LayoutInflater) HomeActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.footnote_popup,
                    (ViewGroup) findViewById(R.id.popup_footnote));
            popup = new PopupWindow(layout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, true);
            popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
            txt_footnote=(TextView) layout.findViewById(R.id.text_footnote);
            txt_footnote.setTypeface(malayalamfont);
            popup_close = (ImageButton) layout.findViewById(R.id.btn_close_popup);
            txt_footnote.setText(footnote);

            final WebView footnoteWView = (WebView) layout.findViewById(R.id.footnotePopupWebview);
            footnoteWView.getSettings().setJavaScriptEnabled(true);
           footnoteWView.loadUrl("file:///android_asset/www/footNotePopup.html");
            footnoteWView.clearCache(true);

           footnoteWView.setWebViewClient(new WebViewClient(){
                public void onPageFinished(WebView view, String url){                        footnoteWView.loadUrl("javascript:getFootnote('" + footnote + "')");
                }
            });
            popup_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    popup.dismiss();
                }
            });
        }
        catch (Exception e) {
            e.printStackTrace();
        };
    }

}

請幫忙

嘗試這個。

AlertDialog.Builder alert = new AlertDialog.Builder(this); 
alert.setTitle("Title here");

WebView wv = new WebView(this);
wv.loadUrl("http:\\www.yourweb.com");
wv.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);

        return true;
    }
});

alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int id) {
        dialog.dismiss();
    }
});
alert.show();
public class List extends ActionBarActivity implements OnClickListener {
LinearLayout layoutOfPopup;
PopupWindow popupMessage;
Button popupButton;
WebView popupText;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
init();
popupInit();
public void init() {
    popupButton = (Button) findViewById(R.id.textview1);
    popupText = new WebView(this);
    popupText.setBackgroundColor(Color.TRANSPARENT);
    String text = "<html><body style=\"text-align:justify\"> %s </body></Html>";
    String summary = "Some text go here</body></html>";
    popupText.loadData(String.format(text, summary), "text/html", "utf-8");
    popupText.setVerticalScrollBarEnabled(true);
    popupText.setHorizontalScrollBarEnabled(true);
    insidePopupButton = new Button(this);
    insidePopupButton.setText("(X)Close");
    insidePopupButton.setBackgroundResource(R.drawable.myborder);
    layoutOfPopup = new LinearLayout(this);

    LayoutParams lpView = new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    layoutOfPopup.addView(insidePopupButton, lpView);
    layoutOfPopup.addView(popupText);
    layoutOfPopup.setOrientation(1);
    layoutOfPopup.setBackgroundColor(Color.WHITE);
}

public void popupInit() {
    popupButton.setOnClickListener(this);
    insidePopupButton.setOnClickListener(this);
    popupMessage = new PopupWindow(layoutOfPopup,
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    popupMessage.setContentView(layoutOfPopup);

}
@Override
public void onClick(View v) {
    //Code goes here and to open the show as drop down
and dismiss
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM