Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Changing color of window background when using FLAG_SECURE

Tags:

android

I have a request that when the my Android application is placed into the background that I blank out the screen to hide sensitive data. This was easy enough to implement using the:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

The difficult part appears to be changing the color of that blank screen you get when looking at the apps in the background. By default it appears to be white and I can't seem to find a way to override that. Anyone have any ideas?

like image 754
nwallman Avatar asked Oct 21 '15 01:10

nwallman


People also ask

How do I make my background White on Android?

Use either the Auto or manual mode to remove the background. Tap on the next icon at the top. Tap on Color tab at the bottom. Using sliders, select the color white.

How do you change the background color on Kotlin?

To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.


2 Answers

Unfortunately you can't customize the color of the thumbnail in the recents view.

As you can see in TaskViewThumbnail the default color of the thumbnail (0xffffffff) is hardcoded, so it's not customizable:

/** Updates the paint to draw the thumbnail. */
void updateThumbnailPaintFilter() {
    if (mInvisible) {
        return;
    }
    int mul = (int) ((1.0f - mDimAlpha) * mThumbnailAlpha * 255);
    int add = (int) ((1.0f - mDimAlpha) * (1 - mThumbnailAlpha) * 255);
    if (mBitmapShader != null) {
        mLightingColorFilter.setColorMultiply(Color.argb(255, mul, mul, mul));
        mLightingColorFilter.setColorAdd(Color.argb(0, add, add, add));
        mDrawPaint.setColorFilter(mLightingColorFilter);
        mDrawPaint.setColor(0xffffffff);
    } else {
        int grey = mul + add;
        mDrawPaint.setColorFilter(null);
        mDrawPaint.setColor(Color.argb(255, grey, grey, grey));
    }
    invalidate();
}
like image 111
Mattia Maestrini Avatar answered Oct 11 '22 03:10

Mattia Maestrini


I'm able to change color of window background to "black" when using FLAG_SECURE through AppTheme in styles.xml file via changing theme like this:

<style name="AppTheme" parent="Theme.AppCompat"> 
****
</style>

It can be customizable to any color but I need black, so if you need custom color make further investigation.

like image 31
Hourglasser Avatar answered Oct 11 '22 04:10

Hourglasser