繁体   English   中英

启动屏幕处于活动状态时加载Webview吗?

[英]Load webview while splash screen is active?

我想在启动屏幕处于活动状态时加载我的Web视图吗? 这不仅仅是直接的问题,而是视觉上的问题,但是当在我的应用程序中加载WebView时,屏幕将在2-4秒之间变为空白,直到内容完全加载为止。 时间取决于正在加载的内容的大小。 有人可以帮我吗?

这是MainActivity

   public class MainActivity extends Activity

{

    private static final String MIME_TYPE_EMAIL = null;
    final Activity activity = this;

    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setPluginsEnabled(true);
        webView.setWebChromeClient(new WebChromeClient()); 
        String scandinavianCharacters = null;
        webView.loadDataWithBaseURL(null, scandinavianCharacters, "text/html", "UTF-8", null);
        webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
        webView.setWebChromeClient(new WebChromeClient() {


            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Učitavanje...");
                activity.setProgress(progress * 100);

                if(progress == 100)
                    activity.setTitle(R.string.app_name);
            }
        });

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                try {
                    webView.stopLoading();
                } catch (Exception e) {
                }
                try {
                    webView.clearView();
                } catch (Exception e) {
                }
                if (webView.canGoBack()) {
                    webView.goBack();
                }
                webView.loadUrl("file:///android_asset/greska/greska.html");
                super.onReceivedError(webView, errorCode, description, failingUrl);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });

        webView.loadUrl("http://mysite.com");

    }
    public boolean shouldOverrideUrlLoading(WebView webview, String url)
    { 
        webview.loadUrl(url);
        return true;
    }


    WebView webView;
    @Override
    public void onBackPressed (){

        if (webView.isFocused() && webView.canGoBack()) {
                webView.goBack();       
        }
        else {
                super.onBackPressed();
        }
    }
    public boolean shouldOverrideUrlLoading(webView view, String url) {
        if(url.startsWith("mailto:")){
            MailTo mt = MailTo.parse(url);
            Intent i = IntentSupport.newEmailIntent(MainActivity.this, mt.getTo(), mt.getSubject(), mt.getBody(), mt.getCc());
            startActivity(i);
            view.reload();
            return true;
        }

            else{
                view.loadUrl(url);
            }
            return true;
        }
   ;


public static Intent newEmailIntent(Context context, String address, String subject, String body, String cc) {
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
  intent.putExtra(Intent.EXTRA_TEXT, body);
  intent.putExtra(Intent.EXTRA_SUBJECT, subject);
  intent.putExtra(Intent.EXTRA_CC, cc);
  intent.setType(MIME_TYPE_EMAIL);
  return intent;
}
    }

这是飞溅活动

public class SplashActivity extends Activity {

   private static String TAG = SplashActivity.class.getName();
   private static long SLEEP_TIME = 8;    // Sleep for some time

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar

      setContentView(R.layout.splash);

      // Start timer and launch main activity
      IntentLauncher launcher = new IntentLauncher();
      launcher.start();
   }

   private class IntentLauncher extends Thread {
      @Override
      /**
       * Sleep for some time and than start new activity.
       */
      public void run() {
         try {
            // Sleeping
            Thread.sleep(SLEEP_TIME*1000);
         } catch (Exception e) {
            Log.e(TAG, e.getMessage());
         }

         // Start main activity
         Intent intent = new Intent(SplashActivity.this, MainActivity.class);
         SplashActivity.this.startActivity(intent);
         SplashActivity.this.finish();
      }
   }
}

清单文件

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.emirnp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar" >
        <activity
            android:name="com.emirnp.next.press.SplashActivity">
        <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
              </activity>
        <activity

            android:name="com.emirnp.next.press.MainActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:screenOrientation="portrait" 
            android:hardwareAccelerated="true">
            <intent-filter>
               <action android:name="android.intent.action.MAIN" />
</intent-filter>


        </activity>

    </application>

</manifest>    

我不太了解您的启动画面在做什么。 当我要在打开慢速页面时显示加载屏幕时,我使用以下代码:

ProgressDialog browse_progressDialog;
...

//before load
browse_progressDialog = new ProgressDialog(YourClass.this);
browse_progressDialog.setMessage(getString(R.string.browse_progressbar_working));
browse_progressDialog.setIndeterminate(true);
browse_progressDialog.setCancelable(false);
browse_progressDialog.show();

//on load complete
browse_progressDialog.dismiss();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM