Set Activity Lightness - Android Activity

Android examples for Activity:Activity Background

Description

Set Activity Lightness

Demo Code


//package com.java2s;
import android.app.Activity;

import android.provider.Settings.System;
import android.view.WindowManager;
import android.widget.Toast;

public class Main {

    public static void SetLightness(Activity act, int value) {
        try {//  www .  j  ava 2  s .  com
            System.putInt(act.getContentResolver(),
                    System.SCREEN_BRIGHTNESS, value);
            WindowManager.LayoutParams lp = act.getWindow().getAttributes();
            lp.screenBrightness = (value <= 0 ? 1 : value) / 255f;
            act.getWindow().setAttributes(lp);
        } catch (Exception e) {
            Toast.makeText(act, "", Toast.LENGTH_SHORT).show();
        }
    }
}

Related Tutorials