【问题标题】:Transparent alert dialog activity will not act like dialog when placing admob ad at bottom?将 admob 广告放在底部时,透明的警报对话框活动不会像对话框一样?
【发布时间】:2021-01-23 12:36:09
【问题描述】:

我正在做一个小项目,我坚持横幅广告的实施。当我将 admob 广告放在底部时,警报功能将失去它的工作意味着当我们单击任何角落的屏幕时,此布局将像对话框一样工作,但是当我在其中添加另一个布局时,我在下面实现横幅广告视图,然后此功能不起作用我强行单击后退按钮退出应用程序。我将在下面给出相同的小剪辑,以便您了解击球手来解决我的问题。

这是我的主题.xml

<style name="Transparent" parent="Theme.AppCompat.Light.Dialog">
        <item name="windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
        <item name="windowActionBar">false</item>

    </style>

这是我的布局 xml:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00212121"
    tools:context=".MainActivity">

    <LinearLayout
    
    //some code here

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        >
        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

    </LinearLayout>


</RelativeLayout>

这是我的清单:

 <activity android:name=".Custom_Settings"
            android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar" />
        <activity
            android:name=".MainActivity"
            android:theme="@style/Transparent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

这是我的 java :-

 mAdView = findViewById(R.id.adView);
       AdRequest adRequest = new AdRequest.Builder().build();
       mAdView.loadAd(adRequest);

现在如果你们都不明白上面的问题,那么看看这两个快照,这会让你知道如何解决这个问题。

【问题讨论】:

  • 转到开发者选项并检查显示布局边界现在您将能够看到对话框的布局边界...所以基本上当您在对话框内放置广告时会拉伸以完成屏幕为什么你无法解雇。您还可以通过更改对话的背景颜色来观察对话占用的空间。如果您有任何疑问,请告诉我
  • 非常感谢你给我这些信息,但我希望 admob 广告位于底部,这个椭圆形布局位于中心,每当用户点击屏幕时,它都会像对话框一样关闭。
  • 一种解决方法是在对话的根视图上设置 onClickListner,当他们按下它时,您只需在对话中调用dismiss() 方法。并在中心视图上设置必要的点击监听器。
  • 不,我不想实现这个逻辑,因为用户体验对我来说也很重要。嘿,在 admob 广告实施之前听我的应用程序就像用户点击屏幕上的任意位置然后我的应用程序自动终止但在实施后我没有得到任何响应
  • 我不明白你的 rootview 概念。

标签: java android android-layout banner banner-ads


【解决方案1】:

使用 AgentP 所说的这个概念,这对我有用:-

为您的真实布局提供 id 说:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00212121"
    android:id="@+id/parent_layout"
    tools:context=".MainActivity">

    //some code here


</RelativeLayout>

现在在 oncreate 中声明并初始化这个父视图:-

    RelativeLayout parent_layout;
@Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_main);
         (RelativeLayout)findViewById(R.id.parent_layout);
        //some code here
        }
        parent_layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
                plusbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, Custom_Settings.class);
                startActivity(intent);
                finish();
            }
        });

非常感谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多