How to change status bar color in themeable browser in Android with Ionic?

Viewed 586

I am using themeable browser plugin link for display url in my Ionic application.

Default themeable browser take black color in status bar, and I have to change it. I am trying below code for that but nothing happens.

    Window window = cordova.getActivity().getWindow();

    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
    {
         window.setStatusBarColor(ContextCompat.getColor(cordova.getActivity(), android.R.color.holo_green_dark));
    }

I am changing this code in Android file which is located here:

https://github.com/initialxy/cordova-plugin-themeablebrowser/blob/master/src/android/ThemeableBrowser.java

2 Answers

It seems that the dialog height is incorrectly calculated just fork the plugin and correct the height calculation. The status bar will maintain the color it had before opening the ThemeableBrowser :

    Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    lp.height = size.y;

I modified the source code as below, it worked.

package com.initialxy.cordova.themeablebrowser;

import android.os.Build;
import android.view.Window;
import android.view.WindowManager;
import androidx.core.content.ContextCompat;
import android.view.Display;
import android.graphics.Point;


public class ThemeableBrowser extends CordovaPlugin{

    public String showWebPage(final String url, final Options features) {
    
        Display display = cordova.getActivity().getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(dialog.getWindow().getAttributes());
        lp.width = size.x;
        lp.height = size.y;
        
        Window window = cordova.getActivity().getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            window.setStatusBarColor(ContextCompat.getColor(cordova.getActivity(), android.R.color.white));
        }
        
        dialog.setContentView(main);
        dialog.show();
Related