1

我想在启动画面处于活动状态时加载我的 webview?这更像是一个视觉问题,而不是直接问题,但是当我的应用程序中加载 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>    
4

1 回答 1

0

我不太明白你的启动画面在做什么。当我想在打开慢速页面期间显示加载屏幕时,我使用以下代码:

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();
于 2013-06-25T12:29:41.940 回答