gpt4 book ai didi

java - Android Webview 的启动屏幕

转载 作者:行者123 更新时间:2023-12-01 10:22:03 25 4
gpt4 key购买 nike

我有一个 WebView 应用程序,想要添加一个启动屏幕以在加载页面时显示或在设定的时间内显示。我尝试过其他一些解决方案,但找不到有效的解决方案。如果有必要知道的话,我的启动图像是splash.png,位于drawable文件夹中。

这是我的 MainActivity.java

public class MainActivity extends Activity {

private GoogleApiClient client;

@Override
public void onBackPressed()
{
WebView webView = (WebView) findViewById(R.id.webView);
if(webView.canGoBack()){
webView.goBack();
}
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}

this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Tap Twice To Exit", Toast.LENGTH_SHORT).show();

new Handler().postDelayed(new Runnable() {

@Override
public void run() {
doubleBackToExitPressedOnce=false;
}
}, 2000);
}

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


WebView view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.setWebViewClient(new MyBrowser());

client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
if(isNetworkStatusAvialable (getApplicationContext())) {
view.loadUrl("file:///android_asset/index.html");
} else {
view.loadUrl("file:///android_asset/error.html");

}
}
public static boolean isNetworkStatusAvialable (Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null)
{
NetworkInfo netInfos = connectivityManager.getActiveNetworkInfo();
if(netInfos != null)
if(netInfos.isConnected())
return true;
}
return false;
}
@Override
public void onStart() {
super.onStart();

client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW,
"MLINKS",
Uri.parse("http://host/path"),

Uri.parse("android-app://PACKAGE-NAME/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}

@Override
public void onStop() {
super.onStop();

Action viewAction = Action.newAction(
Action.TYPE_VIEW,
"MLINKS",
Uri.parse("http://host/path"),
Uri.parse("android-app://PACKAGE-NAME/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}

private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

boolean doubleBackToExitPressedOnce = false;

}

感谢您的帮助!

最佳答案

编辑:

定义进度对话框:

    private ProgressDialog pd;

然后在你的里面:

view.setWebViewClient(new MyBrowser() {

插入:

        @Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pd.show();
}

@Override
public void onPageFinished(WebView view, String url) {
pd.dismiss();
}

关于java - Android Webview 的启动屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35530789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com