将AdMob广告添加到我的应用中

时间:2017-07-24 16:41:00

标签: android admob ads

我正在学习从在线教程开发Android应用程序,我从“stackoverflow”得到了很多答案,非常感谢网站及其用户的帮助。

这是我对这个社区/论坛的第一个问题。但是,我在这个问题的不同网站上得到了很多答案和教程,但没有运气。

简单地说,我想将AdMob广告添加到我的应用中。它们必须出现在应用程序的所有页面/活动中。

请参阅下面提到的应用代码。如果有人可以提供包括admob在内的代码,那将会很有帮助!

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:ads="abc"
    tools:context="com.example.bhagdev.transparentbuttons10.MainActivity"
    android:background="@drawable/j3"
    tools:ignore="NamespaceTypo">



    <ScrollView
        android:layout_width="368dp"
        android:layout_height="495dp"
        tools:layout_editor_absoluteY="8dp"
        tools:layout_editor_absoluteX="8dp"
        tools:ignore="MissingConstraints">

<RelativeLayout
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="8dp"
    tools:layout_editor_absoluteX="8dp"
    tools:ignore="MissingConstraints">


    <Button
    android:id="@+id/button1"
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    android:background="@drawable/button_bg_transparent"
    android:text="@string/button1"
    android:textAlignment="center"
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:textSize="30sp"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="-3dp"
    android:onClick="next1"/>



    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button1"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button2"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp"
        android:onClick="aarti"/>

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button2"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button3"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp"
        android:onClick="Thal"/>

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button3"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button4"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button4"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button5"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button5"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button6"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button6"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button7"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button7"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button8"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
    android:id="@+id/button9"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/button8"
    android:background="@drawable/button_bg_transparent"
    android:text="@string/button9"
    android:textAlignment="center"
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:textSize="30sp"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button9"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button10"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button11"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button10"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button11"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
    android:id="@+id/button12"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/button11"
    android:background="@drawable/button_bg_transparent"
    android:text="@string/button12"
    android:textAlignment="center"
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:textSize="30sp"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button13"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button12"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button13"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button14"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button13"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button14"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <Button
        android:id="@+id/button15"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/button14"
        android:background="@drawable/button_bg_transparent"
        android:text="@string/button15"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="-3dp" />

    <!-- view for AdMob Banner Ad -->
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" />


</RelativeLayout>
</ScrollView>

</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:1)

关于AdMob名为

的非常酷的内容,没有太多的出版物
  

nativeAdsExpress

...但是这种广告非常易于实施,更具吸引力,可以带来更多收入,并且在您的应用中具有更加清晰的集成和完整性。 我强烈建议您使用它,它实现起来非常简单,正如其名称所示,它表达了#39;。 看看here