Webview导致页面上各种元素的背景图像变黑 [英] Webview causing blackening of background images of various elements on page

查看:117
本文介绍了Webview导致页面上各种元素的背景图像变黑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

横幅广告到目前为止一直运作良好.我注意到,每次横幅广告中的动画发生时,都会发生闪烁.

The banner ads were working all good till today. I noticed there is flickering happening everytime the animation happens inside banner ad.

这会影响Fragment/Activity中所有导入和加载AdMob Fragment的元素的背景区域

This is affecting the background regions of all elements inside Fragment/Activity wherever AdMob Fragment is imported and loading


class AdBFiller : Fragment() {
    private lateinit var mAdView: AdView
    private val mAppUnitId: String = "ad-code"
    var fragContext: Context? = null

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val adFrag = inflater.inflate(R.layout.banner_filler, container, false)
        fragContext = context

        initializeBannerAd()

        viewAppender(fragContext!!, adFrag)

        loadBannerAd()
        return adFrag
    }

    private fun initializeBannerAd() {
        MobileAds.initialize(fragContext!!)
    }

    private fun loadBannerAd() {
        val adRequest = AdRequest.Builder().build()
        mAdView.loadAd(adRequest)
    }

    fun viewAppender(contxt: Context, adFrag: View) {
        mAdView = AdView(contxt)
        mAdView.setAdSize(AdSize.BANNER)        // also same issue with SMART_BANNER
        mAdView.setAdUnitId(mAppUnitId)

        (adFrag as FrameLayout).addView(mAdView)
    }

    override fun onDestroyView() {
        mAdView.destroy()
        super.onDestroyView()
    }

    override fun onDestroy() {
        mAdView.destroy()
        super.onDestroy()
    }

    override fun onResume() {
        super.onResume()
        mAdView.resume()
    }


    override fun onPause() {
        super.onPause()
        mAdView.pause()
    }

}

布局(banner_filler)如下:

Layout (banner_filler) is as follows:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".activities.AdBFiller"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</FrameLayout>

代替使用的电话是

 private fun inflateAds() {
        supportFragmentManager
            .beginTransaction()
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
            .add(R.id.adStub, AdBFiller())
            .commit()
    }

adStub是一个FrameLayout

adStub is a FrameLayout

我猜这是由于AdMob代码而自动发生的,因为它运行了好几天.如何隔离应用程序免受这些影响?

I guess this is automatically happening because of AdMob code, as it was working good for many days. How to insulate app, from the impact of these?

尽管视频中的影响很小,但我的其他页面受到的影响很大

Although effect is minor in the video, my other pages are greatly affected

事实证明,这是我的移动设备/制造商特有的问题,并且是由于页面上加载了WebView.由于广告使用的是网络视图,因此它可能是导致广告植入代码中存在问题的原因

Turns out this is an issue specific to my mobile/manufacturer and because of WebView loading on the page. Since Ads use webview, it appeared as the cause of issue lied within the Ad injected code

型号:Honor Huawei-9N,
LLD-AL20,
EMUI 9.1.0,
Android版本9

Model: Honor Huawei - 9N,
LLD-AL20,
EMUI 9.1.0,
Android Verion 9

详细信息:

webview的内容必须完成加载才能开始此问题.一些观点相对不受影响.对于页面的每个加载,页面的那些相同元素都会受到影响,即,固定的复制意味着页面上的50个元素中的每一个都受到影响,而固定的20个元素都受到影响.

The content of webview has to finish loading for this problem to start. Some views are relatively unaffected. For every load of page, those same elements of the page are affected i.e. fixed reproduction means out of 50 elements on page, everytime those fixed 20 are affected.

我想我必须定位&向WebView充气是一种不会干扰其余元素的方式.

I guess I have to position & inflate WebView is a manner which doesn't interfere with rest of elements.

在片段的Root ConstrainLayout关闭之前,Webview或广告是最后一个元素.

Webview or ads are last element just before closing of the Root ConstrainLayout for the Fragment.

有人找到解决此问题的方法吗?

Has anyone found fix for issue like this?

推荐答案

解决了:

android:layerType =软件"

这篇关于Webview导致页面上各种元素的背景图像变黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆