0

I am working on small project and i stuck on banner ads implementation. When i place admob ad below to bottom then alert functionality will loose it working means when we click on screen in any corner then this layout will working like dialog but when i add another layout inside this i implement banner adview below then this functionality is not working and i forcefully click the back button to exit the app. I will give small clip for the same in below so that you can understand batter to resolve my issue.

This is my theme.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>

This is my layout 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>

This is my manifest:

 <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>

This is my java :-

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

Now if you all not understand this above question then see this two snap this will give you an idea how to resolve this problem.

  • go to developer options and check show layout boundaries now you will be able to see the layout boundary of the dialogue... so basically when you put an ad inside the dialogue is stretched to complete the screen that's why you are unable to dismiss . You can also observe space taking by dialogue by changing bg color of dialog. Let me know if you have any doubt – AgentP Jan 23 '21 at 13:03
  • Thank you so much for giving me this information but i want admob ad to bottom and this oval layout at centre and whenever user click on screen it will close like dialog. – PArikshit KAmat Jan 23 '21 at 13:08
  • 1
    One workaround would be to set onClickListner on the root view of your dialogue when they press on it you just call dismiss() method in your dialog. and also set necessary click listeners on the center view. – AgentP Jan 23 '21 at 13:10
  • No I don't want this logic to implement because user experience will also matter to me. Hey listen before admob ad implementation my app works like whenever user click anywhere on screen then my app automatically terminated but after implementation I got no respone – PArikshit KAmat Jan 23 '21 at 13:21
  • I don't understand your rootview concept. – PArikshit KAmat Jan 23 '21 at 13:25
  • root view means the toppost tag of your layout. suppose you have layout add click listner on relative layout – AgentP Jan 23 '21 at 13:30
  • Then if I set onclicklistner to parent layout then if anyone click or change seekbar state then what will happen? May be it will forcefully close. – PArikshit KAmat Jan 23 '21 at 13:35
  • I guess not that won't happen but let me know once if that happen – AgentP Jan 23 '21 at 13:37
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227749/discussion-between-parikshit-and-agentp). – PArikshit KAmat Jan 24 '21 at 08:33

1 Answers1

0

Use this Concept said by AgentP and this works for me:-

give id to your realtive layout say:-

<?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>

Now declare and initialize this parent view in 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();
            }
        });

Thanks a lot!