簡體   English   中英

初始屏幕中的離子狀態欄顏色

[英]Ionic Status bar color in splash screen

我正在使用 ionic 3 開發一個簡單的應用程序,該應用程序正在運行,但在啟動畫面期間狀態欄有問題,它是黑色的,我想將顏色更改為與啟動畫面相同的藍色

在此處輸入圖片說明

我嘗試使用 Ionic Native - Splash Screen,它改變了狀態欄的顏色,但在啟動畫面之后

在此處輸入圖片說明

這是代碼

initializeApp() {
    this.platform.ready().then(() => {


      this.statusBar.overlaysWebView(false);
      this.statusBar.backgroundColorByHexString('#002e5b');
      this.keyboard.disableScroll(true);
    });
  }

有沒有辦法實現這一目標? 謝謝。

我也有同樣的問題。 我用叉子把它修好了:

https://github.com/goinnn/cordova-plugin-splashscreen/tree/4.0.0%23colors

安裝這個 fork:

ionic cordova plugin rm cordova-plugin-splashscreen
ionic cordova plugin add https://github.com/goinnn/cordova-plugin-splashscreen.git#4.0.0#colors

如果您收到此錯誤:

Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.

另一次(非常瘋狂):

ionic cordova plugin add https://github.com/goinnn/cordova-plugin-splashscreen.git#4.0.0#colors

在您的 config.xml 中:

<platform name="android">
    <preference name="SplashStatusBarBackgroundColor" value="#YOUR_COLOR" />
    <preference name="SplashNavigationBarBackgroundColor" value="#YOUR_COLOR" />

添加截圖

平台加載時顯示Splash screen 當平台准備好時,狀態欄顏色將為#002e5b

this.platform.ready().then(() => {
  this.statusBar.overlaysWebView(false);
  this.statusBar.backgroundColorByHexString('#002e5b');
  this.keyboard.disableScroll(true);
});

我認為在這個方法this.platform.ready()之前沒有辦法訪問platform

如果您以單一顏色作為背景,請將狀態欄顏色更改為相同。

對於Android,在styles.xml添加以下內容(我顯示的是白色背景的狀態欄)

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
        <item name="android:statusBarColor">@android:color/white</item>
    </style>

    <style name="AppTheme.NoActionBarLaunch" parent="AppTheme.NoActionBar">
        <item name="android:statusBarColor">@android:color/white</item>
    </style>

我不知道這是否是正確的方法,但我沒有找到另一種方法。

這就是我所做的:

1-我刪除了“閃屏”插件並再次添加,但這次是這個分支。

離子cordova插件添加https://github.com/goinnn/cordova-plugin-splashscreen.git#4.0.0#colors

2- 然后在這個路徑:platforms\\android\\app\\src\\main\\java\\org\\apache\\cordova\\splashscreen.java

更改這些代碼行:

 // Inspirated in https://github.com/apache/cordova-plugin-splashscreen/pull/124/files
            String statusBarColor = preferences.getString("SplashStatusBarBackgroundColor", "#000000");

            if (statusBarColor != null && !statusBarColor.isEmpty() && Build.VERSION.SDK_INT >= 19) {

                splashWindow.clearFlags(0x04000000);
                splashWindow.addFlags(0x80000000);
                try {
                    // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
                    splashWindow.getClass().getMethod("setStatusBarColor", int.class).invoke(splashWindow, Color.parseColor(statusBarColor));
                } catch (Exception ignore) {
                    // this should not happen, only in case Android removes this method in a version > 21
                    LOG.w("SplashScreen StatusBarColor", "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);
                }
            }

3-在 config.xml 文件中添加此首選項:

<preference name="SplashStatusBarBackgroundColor" value="#50ABC5" />

是的,這對我有用。

這個問題仍然存在,我試圖找到黑條的來源。

一種。 在文件 splashscreen.java 中,默認主題 android.R.style.Theme_Translucent_NoTitleBar 被加載以構建對話,這當然會覆蓋您之前設置的所有內容。 我解決了它以覆蓋此文件以訪問我自己的模塊樣式。

            // Create and show the dialog
            splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM