Google admob banner ad changes imageView color

I have implemented test banner ads in my project and they work, but when the banner ad gets loaded the color of the imageview that is also in my activity gets darker, after some time the color of my imageview changes back to normal. Is something wrong with my code or could this be an sdk related problem? Here is how it looks: (Normal imageview) , (Imageview when ad is loaded)

here is my code:

<androidx.constraintlayout.widget.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"
tools:context=".YouAreDream">


<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"
    app:adSize="BANNER"
    app:adUnitId="ca-app-pub-3940256099942544/6300978111"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/constraintLayout2"
    app:layout_constraintVertical_bias="0.42000002"></com.google.android.gms.ads.AdView>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constraintLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="100dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

    <ImageView
        android:id="@+id/imageViewYou"
        android:layout_width="321dp"
        android:layout_height="311dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.13999999"
        app:srcCompat="@drawable/dream"/>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/Dream"
        android:textColor="@color/black"
        android:textSize="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageViewYou"
        app:layout_constraintVertical_bias="0.32999998" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Q_Dream"
        android:textSize="24dp"
        android:textStyle="italic"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintVertical_bias="0.19999999" />

        </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>

Here is my java code:

package com.example.minecraftstreamertest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;

   public class YouAreDream2 extends AppCompatActivity {
   ImageView mImageView;
   AdView mAdView;

   @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_you_are_dream2);
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });

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

    mImageView = (ImageView) findViewById(R.id.imageViewYou);
    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
    mImageView.setAnimation(animation);
    mImageView.clearColorFilter();


}
}

Here is my Manifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.minecraftstreamertest">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MinecraftStreamerTest"
    >
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-7897828714906116~2778343400"/>
    <activity android:name=".YouAreDream2"></activity>
    <activity
        android:name=".YouAreBadboyhalo"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreQuackity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreFundy"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreTubbo"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreWilbur"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreGeorge"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouArePhilza"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreTommy"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreRanboo"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreJschlatt"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreSlime"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreKarl"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreSapnap"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreTechno"
        android:screenOrientation="portrait" />
    <activity
        android:name=".YouAreDream"
        android:screenOrientation="portrait" />
    <activity
        android:name=".TestActivity"
        android:screenOrientation="portrait" />
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Answer

I solved the problem! it seems to be some kind of layer bug but I’m not sure. this is the one line i needed to add in my java file:

mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

here is the java file

public class YouAreWilbur extends AppCompatActivity {
ImageView mImageView;
AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_you_are_wilbur);
    mImageView = (ImageView) findViewById(R.id.imageViewYou);
    Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
    mImageView.setAnimation(animation);
    MobileAds.initialize(this, new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(InitializationStatus initializationStatus) {
        }
    });

    mAdView = findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

I found how to fix the bug on this page: https://issuetracker.google.com/issues/36996575

Leave a Reply

Your email address will not be published. Required fields are marked *