最近,我一直在尝试将admob
添加到我的Google Play商店应用中。
我知道我的广告隐藏在WebView
下,因为当我删除WebView
代码时,我可以看到该广告。但是,当我替换WebView
时,广告会再次隐藏。如何防止广告被隐藏?
以下是我的java代码:
public class MainActivity extends ActionBarActivity {
private android.webkit.WebView mWebview;
private Toast toast;
private long lastBackPressTime = 0L;
int dar = 0;
private ProgressDialog mDialog;
private Menu mymenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressDialog pd = ProgressDialog.show(MainActivity.this, "", "U5N|tech, loading...", true);
mWebview = (WebView) findViewById(R.id.webView);
mWebview = new android.webkit.WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true);// enable javascript
final Activity activity = this;
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(android.webkit.WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pd.show();
}
@Override
public void onPageFinished(WebView view, String url) {
pd.dismiss();
String webUrl = mWebview.getUrl();
}
});
mWebview.loadUrl("http://yousif.u5n.co.uk/dictionaryapp");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// don't touch anything above this line
setContentView(mWebview);
//loads webpages in webview instead of launching browser
}