Luke
Luke

Reputation: 6315

How can I check the status bar colour in Android?

How can I check the status bar colour in Android?

Why do I need to check this? I have created my status bar icons as per the design guidelines however on some devices (Samsung Galaxy S) the status bar is black and it is running Android 2.1.

The recommendations for the status bar icons look great on Android 2.3 (Nexus S) and within the emulator (earlier Android 2.1) with the default light grey status bar. However the black icons that are recommended for pre-2.3 don't look clear on the Samsung Galaxy S.

I would like to provide a white icon if the Android is running 2.1 or 2.2 with a black status bar.

Basically the problem is that the Android design guidelines don't really cover the phones that changed the UI like the Samsung Galaxy S. For example the Samsung Galaxy S running Android 2.1 should have a light grey status bar but it has a black one. This doesn't fit in well with Google's provided design guidelines.

Upvotes: 3

Views: 3921

Answers (3)

Boguś
Boguś

Reputation: 150

I've developed the following method to guess light value of a status bar background. It actually gets background color of a status bar item, but I assume the whole status bar should have similar color. I use this method to distinguish, whether to load black or white version of my status notification icon.

/**
 * Returns estimated value of the lightness of the status bar background
 * @return
 */
private int getStatusBarBackgroundLightValue()
{
    // better this than nothing
    Drawable bg = getResources().getDrawable(android.R.drawable.status_bar_item_background);
    int height = Math.max(1, bg.getIntrinsicHeight());
    int width = Math.max(1, bg.getIntrinsicWidth());
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    bg.setBounds(0, 0, width, height);
    bg.draw(canvas);

    long sum = 0;
    for (int x=0; x<width; x++){
        for (int y=0; y<height; y++){
            int color = bitmap.getPixel(x, y);
            int r = (color >> 16) & 0xFF;
            int g = (color >> 8) & 0xFF;
            int b = (color) & 0xFF;
            int max = Math.max(r, Math.max(g, b));
            int min = Math.min(r, Math.min(g, b));
            int l = (min + max)/2;
            sum = sum + l;
        }
    }
    bitmap.recycle();
    bitmap = null;
    canvas = null;
    bg = null;
    sum = sum / (width * height);
    // should be [0..255]
    return (int)Math.min(255, Math.max(sum, 0));
}

Upvotes: 2

rangeOShun
rangeOShun

Reputation: 63

With adb (you'll find in android development kit) with "pull" command, or just a root file manager, you need to access /system/framework/framework-res.apk. Decompress, it's like zip use(!) apktool. Inside, you'll find the bitmaps of the graphics. Select the ones, containing "statusbar", you just look at them, and you'll see if you want to mass with it, or not.

The tricky part is to get them back, for what you'll need to recompress it, with apktool. The bitmaps have an extra line, with info on streching them. Apktool gets rid of those, or better put, just hides them.

The really hard part is, where you change the clock, and notification colors, from white to black, and for that you'll need to modify classes.dex, whitch part I was stuck.

The easy method is to download and install CyanogenMod, it lets you access these parameters.

Cheers.

Upvotes: 1

Dr.J
Dr.J

Reputation: 1218

Usually you are suppose to bind this via the manifest file but there is a way to get the value: Use the Build.VERSION.SDK_INT and check it against the Build.VERSION_CODES, http://developer.android.com/reference/android/os/Build.VERSION.html

you can get the more interesting read from an android dev blog post here

--edit--

You will have to figure out what device you are on from BUILD but don't forget people have themes as well...

Short of ripping up the framework and the status bar app, that is going to be the best... here is a link if you want to try digging into the StatusBar and getting it from the raw Framework.jar...

Here is a link to a guy who mentions how he handled playing with the status bar.

Upvotes: 1

Related Questions