加入谷歌广告的Andr​​oid应用 [英] adding google ads to android app

查看:154
本文介绍了加入谷歌广告的Andr​​oid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绑谷歌广告添加到我的应用程序(这是我第1次)。我已经添加的jar文件也。

i am tying to add google ads to my app(this is my 1st time). i have added the jar file also.

下面是XML。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/headerbgcolor"
        android:weightSum="1" >

        <Button
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:text="@string/back" 
            android:onClick="finishActivity"/>

        <TextView
            android:id="@+id/headertitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="0.6"
            android:gravity="center"
            android:text="@string/header_title" />

        <Button
            android:id="@+id/home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:text="@string/home" />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="320dp"
        android:scrollbarAlwaysDrawVerticalTrack="true" >
    </ListView>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


        <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="a14f26e5d930307"
        ads:loadAdOnCreate="true"
        ads:testDevices="AVD_for_4in_WVGA_Nexus_S,5554" />



    </RelativeLayout>

</LinearLayout>

但我不能在我的类来定义AdView中,当我试图在类中定义它。

but i am not able to define adview in my class, when i am trying to define it in the class.

这是我的班级我在哪里试着来定义。

here is my class where i am tryin to define.

public class Cities extends Activity {

    Button btnback = null;
    Button btnhome = null;
    TextView headertitle = null;
    ListView lstcities;
    ImageView imgfooter;
    AdView adView; 
    public String BtnSelected; 

我得到错误的AdView解决不了打字,当我试图定义

i am getting error Adview cannot be resolved to type, when i'm trying to define

AdView adview;

什么是poblem?

what is the poblem?

推荐答案

我已经使用这个jar文件 - GoogleAdMobAdsSdk-4.0.4.jar

I have used this jar file - GoogleAdMobAdsSdk-4.0.4.jar

你今年进口线

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;


        AdView adView = new AdView(this, AdSize.BANNER,
                    getString(R.string.publisherID));


        LinearLayout layout = (LinearLayout) findViewById(R.id.imgBanner);
        layout.addView(adView);

        AdRequest adRequest = new AdRequest();
        adRequest.setTesting(true);
        // Start loading the ad in the background.
        adView.loadAd(adRequest);

在XML我刚才写本

<LinearLayout
    android:id="@+id/imgBanner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />

和清单文件

<activity
    android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode" >
</activity>

这篇关于加入谷歌广告的Andr​​oid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆