我的Webview应用停留在初始屏幕上,并且广告显示“初始屏幕后面”

时间:2019-05-22 09:47:16

标签: java android android-layout webview admob

我正在制作博客URL的Webview应用程序。我对其进行了测试,然后生成了一个签名的apk。到这里为止一切正常,然后我注意到当我旋转屏幕时会重新加载。我去搜索并解决了问题,但是:

-该应用程序停留在初始屏幕上。 {我之后添加了进度条。 } -该应用程序的进度栏不起作用。

-该应用程序在旋转到横向时会在初始屏幕后面显示广告横幅

我处理过布局部分,根据我的知识,我查看了未发现任何错误的代码。现在,我对下一步的工作一无所知。

我知道我们不应该粘贴整个文件,即使那样,

主要活动Java

int[] array1 = new int[] { 1,2,3,4,5,6,7,8,9,10 };
        for (int i = 0; i < array1.Length; i+=2)
        {
            try
            {
                Console.WriteLine(array1[i] + "  " + array1[i+1]);

            }
            catch (System.IndexOutOfRangeException)
            {
               System.Console.WriteLine(array1[i]);
                Console.ReadLine();
            }
        }

主要活动的布局

public class MainActivity extends AppCompatActivity {
    private AdView mAdView;


    String ShowOrHideWebViewInitialUse = "show";
    private WebView webview;
    private ImageView spinner;
    private ProgressBar progressBar;

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

        webview =(WebView)findViewById(R.id.webView);
        progressBar = (ProgressBar)findViewById(R.id.progressBar1);
        webview.setWebViewClient(new CustomWebViewClient());


        MobileAds.initialize(this, "ca-app-pub-1137704633163909~7931098472");

        AdView adView = new AdView(this);
        adView.setAdSize(AdSize.SMART_BANNER);
        adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

        webview = (WebView) findViewById(R.id.webView);
        spinner = (ImageView) findViewById(R.id.imageView2);
        webview.setWebViewClient(new CustomWebViewClient());
        webview.getSettings().setSupportZoom(true);
        webview.getSettings().setBuiltInZoomControls(true);
        webview.getSettings().setDisplayZoomControls(false);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);

        webview.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent,
                                        String contentDisposition, String mimetype,
                                        long contentLength) {


                if(savedInstanceState==null){
                    webview.post(new Runnable() {
                        @Override
                        public void run() {
                            webview.loadUrl("https://mygameboxapp.blogspot.com/p/gamebox-tons-of-games.html");
                        }
                    });
                }

            }
        });
    }




    // This allows for a splash screen
    // (and hide elements once the page loads)
    private class CustomWebViewClient extends WebViewClient {



        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            view.loadUrl("about:blank"); webview.loadUrl("file:///android_asset/myerrorpage.html");

        }

        @Override
        public void onPageStarted(WebView webview, String url, Bitmap favicon) {

            // only make it invisible the FIRST time the app is run
            if (ShowOrHideWebViewInitialUse.equals("show")) {
                webview.setVisibility(webview.INVISIBLE);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {

            ShowOrHideWebViewInitialUse = "hide";
            spinner.setVisibility(View.GONE);

            view.setVisibility(webview.VISIBLE);
            super.onPageFinished(view, url);


        }
    }



    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState )
    {
        super.onSaveInstanceState(outState);
        webview.saveState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState)
    {
        super.onRestoreInstanceState(savedInstanceState);
        webview.restoreState(savedInstanceState);
    }


我也玩清单游戏

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    tools:context="com.mannat.gamebox.MainActivity">



    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/webView"
        android:visibility="gone" />

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/splahscreen"
        android:contentDescription="@string/todo" />


    </RelativeLayout>

我希望该应用能够轻松运行,希望你们能帮助我。

我的ZIP项目:https://drive.google.com/file/d/1VWtx1P1apuXe0Hdj4XNLEyM6yCoooQMi/view?usp=sharing

0 个答案:

没有答案