相关疑难解决方法(0)

加载Admob/Firebase广告后,DayNight主题中的颜色变暗

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

屏幕:

在此输入图像描述

那些不正确的颜色来自"notnight"值.当我关闭应用程序并再次运行它一切都很好.当我杀了应用程序时,我有同样的情况.

活动代码:

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");
        } …
Run Code Online (Sandbox Code Playgroud)

android admob android-theme firebase

9
推荐指数
1
解决办法
1020
查看次数

调用 AppCompatDelegate.setDefaultNightMode 后重新创建启动画面

我正在使用AppCompatDelegate.setDefaultNightMode(mode);在我的 Android 应用程序中设置夜间模式,每当用户在其设备上的共享首选项中选择首选项配置的任何模式时,现在当应用程序从 Splash 启动时,我使用共享首选项来设置 UI 模式屏幕活动,该活动正在重新创建,然后我的应用程序有 2 个实例,因为启动屏幕意图登陆活动。

这是我的 SplashScreen.java

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        SharedPreferences prefs = getSharedPreferences(UI_MODE, MODE_PRIVATE);
        name = prefs.getString("uiMode", "System");
        applyUI();
        fireSplashScreen();
    }

    private void applyUI() {
        if (name.equals("Dark")){
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        }
        else if (name.equals("Light")){
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
        else {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
        }
 private void fireSplashScreen() {
         Intent i = new Intent(SplashScreen.this, Landing.class);
            startActivity(i);
            finish();
    }
Run Code Online (Sandbox Code Playgroud)

我该如何避免创建登陆活动的多个实例?

performance android android-layout android-studio

2
推荐指数
1
解决办法
1581
查看次数