我已添加到我的应用AdMob中。
@Override
public void onResume()
{
super.onResume();
if(adView == null)
{
// Create the adView
adView = new AdView(this, AdSize.BANNER,LabelsShow.AD_UNIT_ID_GOES_HERE);
// Lookup your LinearLayout assuming it’s been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout)findViewById(R.id.l_eadds);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
}
的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:id="@+id/l_eadds"
android:background="@drawable/bgg"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="53dip" android:background="@drawable/bg_fill">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="47dp"
android:text=""
android:id="@+id/editText" android:layout_toRightOf="@+id/textView" android:layout_alignParentTop="true"
android:layout_marginTop="6dp" android:layout_marginLeft="6dp" android:layout_marginBottom="3dp"
android:layout_weight="1"
android:drawableLeft="@drawable/e"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="@string/search"
android:id="@+id/look" android:layout_alignParentLeft="true"
android:layout_alignBaseline="@+id/textView" android:layout_marginLeft="6dp"
android:minWidth="100dip" android:background="@drawable/btn_no"
android:layout_marginRight="6dp" android:layout_marginTop="6dp" android:layout_marginBottom="6dp"/>
</TableRow>
</LinearLayout>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/webView" android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_below="@+id/look">
<requestFocus />
</WebView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E"
android:id="@+id/textViewik" android:layout_alignParentLeft="true" android:layout_marginLeft="11dp"
android:layout_alignParentTop="true" android:layout_marginTop="19dp"/>
</LinearLayout>
用两个词来说:在我的应用程序中的Android 4+ admob中。但在Android 2.3中不起作用。 我用4部手机测试了它。两个4+和两个2.3。 2.3没有横幅的活动( 在其他应用程序中,admob可以使用。
答案 0 :(得分:1)
我使用不同的策略。
在xml中:
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:adSize="BANNER"
app:adUnitId="AD_UNIT_ID_GOES_HERE" >
</com.google.ads.AdView>
并在java类中:
package com.example.packagename;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
import android.os.Handler;
public class ClassName extends Activity {
private AdRequest re;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final AdView adview = (AdView) findViewById(R.id.adView);
re = new AdRequest();
adview.loadAd(re);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
re = new AdRequest();
adview.loadAd(re);
handler.postDelayed(this, 15000);
}
}, 15000);
--rest of code
}
希望你能用它。