android - 加载 Admob/Firebase 广告后,DayNight 主题中的颜色不正确

标签 android firebase admob android-theme

我为我的应用程序使用 Theme.AppCompat.DayNight.NoActionBar 主题。当我加载 adMob interstital 时,一些颜色在“夜间”模式下被破坏(即在 RecyclerView 中)。

屏幕:

enter image description here

那些不正确的颜色来自“notnight”值。 当我关闭应用程序并再次运行时,一切正常。 当我终止应用程序时,我遇到了同样的情况。

Activity 代码:

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

最佳答案

这个问题应该是由 WebView 重置 UI 模式引起的,这可以通过手动实例化 WebView 来解决。

执行此操作后我还没有看到问题(在这个特定应用程序的 Application.oncreate() 中):

    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

关于android - 加载 Admob/Firebase 广告后,DayNight 主题中的颜色不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44035654/

相关文章:

firebase - 用户名认证而不是电子邮件

javascript - Vue + 火力地堡 : Users being created but logged in under other users accounts

iphone - 无法从 http ://www. admob.com 获取发布商 ID

ios - AdMob 插页式错误 "Request Error: No ad to show"

android - 在Android中,当Google Play服务已使用时如何添加Admob

android - 无法取消选中 setMultiChoiceItems 中的 selectedItems

java - 引用外部 Java 和 Android 库

android - 得到 ArithmeticException : divide by zero, 但我没有在任何地方除以零

java - 将 Html.fromHtml 与 android 8 十六进制数字颜色资源一起使用

javascript - Firebase注册一次,登录不同应用