Google admob横幅广告改变imageView颜色



我已经在我的项目中实现了测试横幅广告,它们工作,但是当横幅广告加载的图像视图的颜色,也是在我的活动变暗,一段时间后,我的图像视图的颜色变回正常。是我的代码有问题,还是这可能是一个sdk相关的问题?它看起来是这样的:(Normal imageview),(加载广告时的imageview)

下面是我的代码:
<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>
下面是我的java代码:
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();

}
}

这是我的舱单代码:

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

我解决了这个问题!这似乎是某种层错误,但我不确定。这是我需要在Java文件中添加的一行:

mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

下面是Java文件

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);
}

我找到了如何修复这个错误在这个页面:https://issuetracker.google.com/issues/36996575

我有同样的问题。我试了很多,但还是没能弄明白。问题的原因是横幅广告。实际上,如果横幅中存在任何动画,imageview的黑暗会随着动画的变化而变化,就像闪光灯一样。

相关内容

  • 没有找到相关文章