簡體   English   中英

WebView 不顯示 admob 橫幅廣告添加

[英]WebView Not show when admob banner ads add

我不知道為什么當我放 admob 橫幅廣告時,我的 webView 是 show show

<com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        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>

問題

當我刪除 admob 然后我的 webview 顯示完美

web.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="5dp">

        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:id="@+id/myProcessBar"
            android:layout_weight="0.1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:max="100" 
            android:progress="45"
        />

    </LinearLayout>
    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_below="@+id/pb"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swiperefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        
    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    
        
    </android.support.v4.widget.SwipeRefreshLayout>
    </LinearLayout>
    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        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>
    
</RelativeLayout>

請有人幫助我:-

web_main.java

package com.musicwala.djaman;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import org.apache.http.conn.util.PublicSuffixList;
import android.webkit.DownloadListener;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.app.Dialog;
import android.widget.Toast;
import android.os.Build;
import android.content.pm.PackageManager;
import android.app.DownloadManager;
import android.net.Uri;
import android.webkit.URLUtil;
import android.support.v4.app.ActivityCompat;
import android.Manifest;
import android.view.Menu;
import android.view.MenuInflater;
import java.util.zip.Inflater;
import android.view.MenuItem;
import android.content.Intent;
import android.text.style.UpdateAppearance;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View; 
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class web_main extends Activity
{
    private AdView mAdView;
    ProgressBar superProgressBar;
    WebView superWebView;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    
        // TODO: Implement this method
        setContentView(R.layout.web);
        MobileAds.initialize(this, "ca-app-pub-1075872442233861~4332615881");
        superProgressBar = (ProgressBar) findViewById(R.id.myProcessBar);
        superWebView = (WebView) findViewById(R.id.webview);
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
        //Set Max Progress Bar
        superProgressBar.setMax(100);
        superWebView.loadUrl("http://musicwala.cf");
        superWebView.getSettings().setJavaScriptEnabled(true);
        final SwipeRefreshLayout finalMySwipeRefreshLayout1;
        finalMySwipeRefreshLayout1 = findViewById(R.id.swiperefresh);
        finalMySwipeRefreshLayout1.setColorSchemeColors(Color.BLUE, Color.YELLOW, Color.GREEN);
        finalMySwipeRefreshLayout1.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    // This method performs the actual data-refresh operation.
                    // The method calls setRefreshing(false) when it's finished.
                    
                    superWebView.loadUrl(superWebView.getUrl());
                    
                    //finalMySwipeRefreshLayout1.setVisibility(View.INVISIBLE);
                }
            });
        superWebView.setWebViewClient(new WebViewClient(){
            
                @Override
                public void onPageFinished(WebView view, String url) {
                    finalMySwipeRefreshLayout1.setRefreshing(false);
                    //.setVisibility(View.GONE);
                }
        });
        
        superWebView.setWebChromeClient(new WebChromeClient(){
        
            @Override
            public void onProgressChanged(WebView view,int newprogress){
                super.onProgressChanged(view, newprogress);
                superProgressBar.setProgress(newprogress);
                
                    superProgressBar.setProgressTintList(ColorStateList.valueOf(Color.GREEN));
                    
                    
                
                if(newprogress == 100)
                {
                
                    superProgressBar.setVisibility(view.GONE);
                }
                else
                {
                    superProgressBar.setVisibility(view.VISIBLE);
                }
                
                
            }
            
            
            @Override
            public void onReceivedTitle(WebView view,String title){
                super.onReceivedTitle(view, title);
                getActionBar().setTitle(title);
                getActionBar().setSubtitle("MusicWala");
                getActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED));
            }
            
        });
        superWebView.setDownloadListener(new DownloadListener(){

                @Override
                public void onDownloadStart(String url, String useragent, String contentdisposition, String mimetype, long contentlenth)
                {
                    // TODO: Implement this method
                    alertbox(url,useragent,contentdisposition,mimetype);
                }

                private void alertbox(final String url,final String useragent,final String contentdispositon,final String mimetype)
                {
                    // TODO: Implement this method
                    
                    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(web_main.this);
                    alertDialogBuilder.setCancelable(false);
                    alertDialogBuilder.setTitle("Download");
                    alertDialogBuilder.setMessage("Do You Want To Download");
                    alertDialogBuilder.setPositiveButton("Yes",new DialogInterface.OnClickListener(){
                        @Override
                        public void onClick(DialogInterface Dialog,int which){
                            //Download Start
                            
                            //Checking Android Version
                            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
                                //Androidb Version 6 or upper
                            {
                                if(checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
                                {
                                    //Now Downlaod Start * Permission is granded
                                    downloadStart(url,useragent,contentdispositon,mimetype);
                                }
                                else
                                {
                                    //Permission request
                                    ActivityCompat.requestPermissions(web_main.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                                    Toast.makeText(web_main.this,"Click On Download Button",Toast.LENGTH_SHORT).show();
                                }
                            }
                            else
                            {
                                //Android Version 5 or below
                                downloadStart(url,useragent,contentdispositon,mimetype);
                            }
                            
                        }

                        private void downloadStart(String url, String useragent, String contentdispositon, String mimetype)
                        {
                            // TODO: Implement this method
                            DownloadManager.Request request = new DownloadManager.Request(
                                Uri.parse(url));
                            final String fileName=URLUtil.guessFileName(url,contentdispositon,mimetype);
                            request.allowScanningByMediaScanner();
                            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                            request.setDestinationInExternalPublicDir("/MusicWala",fileName);
                            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                            dm.enqueue(request);
                            Toast.makeText(getApplicationContext(), "Downloading Started...", //To notify the Client that the file is being downloaded
                                           Toast.LENGTH_LONG).show();
                        }
                    });
                    alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener(){
                            @Override
                            public void onClick(DialogInterface Dialog,int which){

                                //Download Cancel
                                Dialog.dismiss();
                            }
                        });
                        alertDialogBuilder.create().show();
                }
                

            
        });
    }

    @Override
    public void onBackPressed()
    {
        // TODO: Implement this method
        //super.onBackPressed();
        if(superWebView.canGoBack()){
            superWebView.goBack();
        }
        else
        {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // TODO: Implement this method
        MenuInflater Inflater = getMenuInflater();
        Inflater.inflate(R.menu.all_menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // TODO: Implement this method
        switch (item.getItemId())
        {
            case R.id.download:
                //Settings Item
                Intent download= new Intent(web_main.this,download.class);
                startActivity(download);
                break;
            case R.id.settings:
                //Settings Item
                Intent setting= new Intent(web_main.this,setting.class);
                startActivity(setting);
                break;
                
            case R.id.update:
                //Update Item

                Intent Update = new Intent(web_main.this,update.class);
                startActivity(Update);
                break;
                
            case R.id.about:
                //Settings Item

                Intent about = new Intent(web_main.this,about.class);
                startActivity(about);
                break;
                
            case R.id.exit:
                //Settings Item
                android.os.Process.killProcess(android.os.Process.myPid());
                System.exit(1);
                break;
        }
        return super.onOptionsItemSelected(item);
    }
    

    
    
}

您的代碼看起來非常干凈和正確,讓我們嘗試更改第一個布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

看看會發生什么

還有你是什么意思

當我刪除 admob

您不是在請求數據(例如通過注釋掉mAdView.loadAd(adRequest); )還是從 XML 中刪除整個<com.google.android.gms.ads.AdView布局?

順便提一句。 刪除您的唯一密鑰和 ID,永遠不要將它們發布到任何地方......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM