gpt4 book ai didi

android - WebView 第一次不加载静态页面

转载 作者:太空狗 更新时间:2023-10-29 15:03:54 27 4
gpt4 key购买 nike

我正在使用两个 webView 在 DialogFragment 内的两个选项卡内显示。我观察到的奇怪行为是,最初,第一个选项卡打开空白( WebView 中没有任何内容)。

当我按下第二个选项卡时,它会正确显示静态页面,然后如果我切换回第一个选项卡,它甚至会正确显示第一个选项卡静态 html。我很难弄清楚为什么它最初不加载第一个选项卡。有什么想法吗?

package in.co.madhur.dashclockfeedlyextension;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.LocalActivityManager;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

public class AboutDialog extends DialogFragment
{
private WebView aboutWebView, whatsNewView;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

View v = LayoutInflater.from(getActivity()).inflate(R.layout.about_dialog, null);
builder.setView(v);

TabHost tabHost = (TabHost) v.findViewById(R.id.about_tab);
aboutWebView = (WebView) v.findViewById(R.id.about_webview);
whatsNewView = (WebView) v.findViewById(R.id.whatsnew_webview);



aboutWebView.setWebViewClient(new MyWebViewClient());

tabHost.setup();

builder.setNeutralButton(android.R.string.ok, new OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();

}
});

builder.setPositiveButton(R.string.feedback_button, new OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int which)
{
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", Consts.MY_EMAIL, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_button));
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));

}
});

builder.setNegativeButton(R.string.rate_button, new OnClickListener()
{

@Override
public void onClick(DialogInterface dialog, int which)
{
Uri uri = Uri.parse("market://details?id="
+ getActivity().getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try
{
startActivity(goToMarket);
}
catch (ActivityNotFoundException e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="
+ getActivity().getPackageName())));
}

}
});

TabSpec aboutTab = tabHost.newTabSpec(Consts.ABOUT_TAG);
aboutTab.setIndicator(getString(R.string.action_about));
aboutTab.setContent(R.id.tab1);
//aboutTab.setContent(intent);

TabSpec whatsnewTab = tabHost.newTabSpec(Consts.WHATS_NEW_TAG);
whatsnewTab.setIndicator(getString(R.string.whatsnew_tab));
whatsnewTab.setContent(R.id.tab2);

tabHost.addTab(aboutTab);
tabHost.addTab(whatsnewTab);



tabHost.setOnTabChangedListener(new OnTabChangeListener()
{

@Override
public void onTabChanged(String tabId)
{
Log.v(App.TAG, tabId);

}
});

aboutWebView.loadUrl(Consts.ABOUT_URL);
whatsNewView.loadUrl(Consts.CHANGES_URL);

return builder.create();
}

private class MyWebViewClient extends WebViewClient
{

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
boolean result = false;

/* ... */
// Return false to proceed loading page, true to interrupt loading

return result;
}
}



}

最佳答案

在创建并初始化对话框(和 WebView)后,在 onViewCreated 方法中覆盖并执行您的加载逻辑。

关于android - WebView 第一次不加载静态页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23768016/

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