Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

android - how to set different title for alert dialog when WebView page is loaded?

I want to set different title for alert dialog when WebView page is loaded but its not working.

here is the code snippet:

final AlertDialog.Builder alert = new AlertDialog.Builder(
        mContext);
// alert.setTitle("Loading...");
final WebView wv = new WebView(mContext);

wv.loadUrl("http://10.0.51.133/androidview/");
wv.getSettings().setJavaScriptEnabled(true);
wv.setVerticalScrollBarEnabled(false);

WebViewClientLoader loader= new WebViewClientLoader(alert);
wv.setWebViewClient(loader);
wv.setWebViewClient(new WebViewClient() {

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        alert.setTitle("Loading...");
        super.onPageFinished(view, url);
    }

    @Override
    public void onPageStarted(WebView view, String url,
            Bitmap favicon) {
        // TODO Auto-generated method stub
        alert.setTitle("Finished");
        super.onPageStarted(view, url, favicon);
    }
});

private class webviewclient extends WebViewClient{

}

wv.loadUrl("file:///android_asset/Like.html");
alert.setView(wv);

alert.show();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Its perfectly work..i am posting after checking-------

public class MyActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView web=new WebView(this);
    web.setWebViewClient(new WebViewClient(){

        @Override
        public void onLoadResource(WebView view, String url) {
            super.onLoadResource(view, url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            alert.setTitle("Pages Finished");
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            alert.setTitle("Pages Started");
        }

    });
    web.setWebChromeClient(new WebChromeClient(){

    });
    web.loadUrl("http://www.google.com");
    builder=new AlertDialog.Builder(this);
    builder.setView(web);
    builder.setTitle("Loading...");
    alert=builder.create();
    alert.show();
}
AlertDialog alert;
Builder builder;
@Override
protected void onDestroy() {
    super.onDestroy();

}

@Override
protected void onPause() {
    super.onPause();
}

}

enter image description here

and then it changes to

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...