自定义警报对话框中的 Admob(广告)

发布于 2024-12-07 14:55:14 字数 2075 浏览 0 评论 0原文

在市场上我看到一个应用程序在警报对话框中显示 admob 。在我阅读 这个这个和<一个href="http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog" rel="nofollow noreferrer">this ,

我仍然不知道如何展示广告在警报对话框中与下面的相同。 (或任何其他方法,可以在警报对话框中显示广告)

在此处输入图像描述

我一直在抓我的头试图弄清楚如何 这样做。

有谁能好心地指导我如何 该怎么做?

XML:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@id/tablayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:myapp="http://schemas.android.com/apk/res/com.xxx.xxx">

    <TableRow>
  <com.admob.android.ads.AdView android:id="@id/myad" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  myapp:backgroundColor="#ff000000" 
  myapp:primaryTextColor="#ffffffff" 
  myapp:secondaryTextColor="#ffcccccc" />
    </TableRow>

</TableLayout>

Java:

 public void onBackPressed() {
    //set up dialog
                Dialog dialog = new Dialog(main.this);
                dialog.setContentView(R.layout.exitdialog);
                dialog.setTitle("This is my custom dialog box");
                dialog.setCancelable(true);


                //set up button
                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                //now that the dialog is set up, it's time to show it    
                dialog.show();
            }
        });
}

谢谢。

In the market I saw an app is displaying admob in the alert dialog . after I reading this and this and this ,

I still can't figure out how to display the ads in alert dialog same like the one below. (or any others method , that can display the ads in a alert dialog)

enter image description here

I've been scratching my head trying to figure out how
to do that.

Could anyone be kind enough to guide me through how
to go about this?

XML :

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@id/tablayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="*"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:myapp="http://schemas.android.com/apk/res/com.xxx.xxx">

    <TableRow>
  <com.admob.android.ads.AdView android:id="@id/myad" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  myapp:backgroundColor="#ff000000" 
  myapp:primaryTextColor="#ffffffff" 
  myapp:secondaryTextColor="#ffcccccc" />
    </TableRow>

</TableLayout>

Java :

 public void onBackPressed() {
    //set up dialog
                Dialog dialog = new Dialog(main.this);
                dialog.setContentView(R.layout.exitdialog);
                dialog.setTitle("This is my custom dialog box");
                dialog.setCancelable(true);


                //set up button
                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                //now that the dialog is set up, it's time to show it    
                dialog.show();
            }
        });
}

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜吻♂芭芘 2024-12-14 14:55:14

我找到了另一个解决方案来做到这一点。

AdMob 为 Android 和 iPhone 网站/网络应用提供 JavaScript 集成解决方案。

而不是使用 XML 和自定义对话框。
我们可以使用 Admob 网络广告和包含 admob 代码的 HTML,并在对话框中使用 webview 加载它。

I found another solution to do this.

AdMob offers a JavaScript integration solution for Android and iPhone sites/web apps.

Instead of using XML and a custom dialog.
We can use Admob web ads and a HTML that contain the admob code and load it with webview in the dialog.

农村范ル 2024-12-14 14:55:14

我相信除非您处于横向模式,否则这是不可能的。原因是广告需要接近设备宽度的内容(在纵向模式下,例如 480),因此当您将其添加到对话框中时,它仅在横向模式下可用

I believe it's not possible unless you're on landscape mode. The reason is that the ad needs something close to the device width (in portrait mode, e.g. 480) for the ad, so it is only available in landscape mode when you're adding it inside a dialog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文