Progress Status in Android App with Iframe a Site

断了今生、忘了曾经 提交于 2019-12-23 04:38:08

问题


I am building one app for my online radio station with iframe the site. But how I will add a progress status or animation image so that it's start on loading & end after load the site ? Here is the code I am using now:

package com.jibon.tarabradio;    
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends Activity {
    @SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webview;
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setLoadWithOverviewMode(true);
        webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
        webview.loadUrl("http://hoicoimasti.com/radio/");      

         }         
}

I also have another problem. When I select one country from drop down menu showing inside the app it's open different browser. How do I stop that & open inside the app ? Thanks in advance.


回答1:


Just did it :) & solved other problem also :)

package com.jibon.tarabradio;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class MainActivity extends Activity {
    WebView webview;
    ProgressBar progressBar;
    @SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        webview = (WebView) findViewById(R.id.webview);
        progressBar = (ProgressBar) findViewById(R.id.progress_bar);

        webview.setWebViewClient(new myWebClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setLoadWithOverviewMode(true);
        webview.getSettings().setUseWideViewPort(true);
        webview.getSettings().setAllowUniversalAccessFromFileURLs(true);
        webview.loadUrl("http://hoicoimasti.com/radio/");


         }

    public class myWebClient extends WebViewClient
    {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            view.loadUrl(url);
            return true;

        }

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

            progressBar.setVisibility(View.GONE);
        }
    }


}


来源:https://stackoverflow.com/questions/20302949/progress-status-in-android-app-with-iframe-a-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!