AdMob in a fragment(片段中的 AdMob)
问题描述
我在我的应用程序中插入了一个 AdMob.但我有一个问题.
I'm inserting an AdMob in my application. but I have a problem about it.
当我在 Eclipse 中插入一些关于它的代码时,我可以在 fragment_03 中看到一条关于构造函数 AdRequest() 不可见"的错误消息,以及错误:解析 XML 时出错:未绑定前缀"来自
所以我附上了 AdMob 的源代码,如下所示.
when I inserted some codes about it in Eclipse, I can see an error message about "the constructor AdRequest() is not visible " in a fragment_03 and "error: Error parsing XML : unbound prefix" from "
so I attached source for the AdMob as follows.
你能给我一个建议吗?
如果您有任何问题,请告诉我.
Let me know if you have any question.
谢谢
fragment_03.java
fragment_03.java
import com.google.ads.AdRequest;
import com.google.ads.AdView;
public class Fragment_03 extends Fragment {
private AdView adView;
private AdRequest adRequest;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_03, container, false);
adRequest = new AdRequest();
adView = (AdView) rootView.findViewById(R.id.fragment_03_admob);
adView.loadAd(adRequest);
return rootView;
}
}
fragment_03.xml
fragment_03.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.ads.AdView
xmlns:ads="schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/fragment_03_admob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/activity_admobID"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</LinearLayout>
AndroidManifest.xml
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
推荐答案
这样改变你的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.ads.AdView
android:id="@+id/fragment_03_admob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="@string/activity_admobID"
app:loadAdOnCreate="true"
app:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</LinearLayout>
您使用了错误的命名空间声明.
You was using a wrong namespace declaration.
这篇关于片段中的 AdMob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:片段中的 AdMob
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01