如何从Window Manager视图中更改Brigthness?

时间:2015-06-15 11:02:24

标签: android android-windowmanager android-seekbar

我在onCrate()里面的Window管理器中添加了一个视图。在这个视图中我使用了一个搜索栏,当搜索栏被更改时,我想相应地将亮度更改为低或高。但是如果我将搜索栏放在窗口管理器以外的任何其他视图中我能够改变亮度但是要求是从窗口管理器视图中调出亮度。请帮帮我。

问题可能是使用两次窗口管理器。一个用于添加窗口管理器,第二个用于更改窗口管理器的亮度属性。当我使用相同的窗口管理器对象并尝试移动seeek bar.i得到execption作为窗口已添加,我们不能在添加窗口管理器后chagne它的属性。

manager = ((WindowManager) getApplicationContext().getSystemService(
                Context.WINDOW_SERVICE));

        localLayoutParams = new WindowManager.LayoutParams();
        localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        localLayoutParams.gravity = Gravity.TOP;
        localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
        localLayoutParams.flags = 0x80000000 | localLayoutParams.flags;
        localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        localLayoutParams.height = (int) (80 * getResources()
                .getDisplayMetrics().scaledDensity);
        localLayoutParams.format = PixelFormat.TRANSPARENT;
        LayoutInflater inflater = getLayoutInflater();
        Constant.lp = localLayoutParams;
        overlay = inflater.inflate(R.layout.systembar_overlay, null);
        linearLayout = new LinearLayout(getApplicationContext());
        linearLayout.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        linearLayout.addView(overlay);
        Animation animation = AnimationUtils.loadAnimation(
                getApplicationContext(), R.anim.fade_in);
        overlay.startAnimation(animation);
        mSeekBarRedLine = (ImageView) overlay.findViewById(R.id.seekbarredline);
        initLayout(overlay);
        manager.addView(linearLayout, localLayoutParams);



@Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub
            localLayoutParams.screenBrightness = progress / 750.0f;
            getWindow().setAttributes(localLayoutParams);
        }

1 个答案:

答案 0 :(得分:0)

如果您将WindowManagerlinearLayoutlocalLayoutParams定义为字段,则可以使用以下方法:

 @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        localLayoutParams.screenBrightness = progress / 750.0f;
        manager.updateViewLayout(linearLayout, localLayoutParams);
    }