加载Admob / Firebase广告后,DayNight主题中的颜色破碎 [英] Broken colors in DayNight Theme after loading Admob/Firebase ad
问题描述
我为我的应用程序使用 Theme.AppCompat.DayNight.NoActionBar
主题。当我加载adMob interstital时,在夜间模式下(即在RecyclerView中)某些颜色被破坏了。
I use Theme.AppCompat.DayNight.NoActionBar
theme for my app. When I load adMob interstital some colors are broken in "night" mode (i.e. in RecyclerView).
屏幕:
那些不正确的颜色来自 nightnight值。
当我关闭应用程序并再次运行时,一切正常。
当我杀死该应用程序时,我的情况也一样。
Those incorrect colors are from "notnight" values. When I close the app and run it again everything is okay. When I kill the app I have the same situation.
活动代码:
public class MainActivity extends AppCompatActivity {
static {
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_AUTO);
}
private ArrayList<String> planetList = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
populateRecycler();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
PlanetAdapter adapter = new PlanetAdapter(planetList, getApplicationContext());
recyclerView.setAdapter(adapter);
InterstitialAd interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-543543543/543543543");
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
}
private void populateRecycler() {
for (int i = 0; i < 20; i++) {
planetList.add("TEST");
}
}
}
当我注释 interstitialAd.loadAd(adRequest)
一切正常。
您可以在此处找到整个项目:
github
You can find whole project here: github
推荐答案
问题可能是由 WebView
重置UI模式引起的,可以通过实例化 WebView
手动。
The issue is supposedly caused by the WebView
resetting the UI mode, and this can be worked around by instantiating WebView
manually.
执行此操作后,我没有看到此问题(在 Application.oncreate()
中特定应用程序):
I haven't seen the issue after doing this (in Application.oncreate()
in this particular app):
if (nightMode != AppCompatDelegate.MODE_NIGHT_NO) {
Log.d(TAG, "Manually instantiating WebView to avoid night mode issue.");
try {
new WebView(getApplicationContext());
} catch (Exception e) {
Log.e(TAG, "Got exception while trying to instantiate WebView to avoid night mode issue. Ignoring problem.", e);
}
}
AppCompatDelegate.setDefaultNightMode(nightMode);
来源: https://groups.google.com/forum/#!msg/google-admob-ads-sdk/OZzHq_-wAFY/ K50jClZcBAAJ
这篇关于加载Admob / Firebase广告后,DayNight主题中的颜色破碎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!