は、新しいクラスAdPreference.javaを作成し、このコードが含まれています:あなたの解像度で
public class AdPreference extends Preference {
public AdPreference(Context context, AttributeSet attrs, int defStyle) {super (context, attrs, defStyle);}
public AdPreference(Context context, AttributeSet attrs) {super(context, attrs);}
public AdPreference(Context context) {super(context);}
@Override
protected View onCreateView(ViewGroup parent) {
// this will create the linear layout defined in ads_layout.xml
View view = super.onCreateView(parent);
// the context is a PreferenceActivity
Activity activity = (Activity)getContext();
// Create the adView
AdView adView = new AdView(activity, AdSize.BANNER, "YOUR_ADMOB_ID_HERE");
((LinearLayout)view).addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
adView.loadAd(request);
return view;
}
}
を、私は、このリンクを見て、私の質問に対する答えが見つからなかった
PS/layout folderは、ad_layout.xmlというタイトルの新しいxmlレイアウトを作成します。そして、このコードが含ま:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
は、その後、あなたの "設定" XMLでのxmlns行の後にこの権利を追加します。あなたのAndroidManifest.xmlで
<com.yourpackagename.AdPreference android:layout="@layout/ad_layout"/>
を
また
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" android:value="false" />
前にこれを追加マニフェストでこれを追加:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
それだけです。それは完全に動作します。
Re:あなたの追加情報:広告が表示されない可能性があります。電話の違いではなく、広告を表示していないためです。私はadmobを使用していますが、要求の約70-80%しか実際には広告表示になりません。そうしないと広告ビューは表示されません。それが役立つかどうかわからない:) – Jay