【问题标题】:Adjust Screen Brightness by scrolling up and down on the screen and without using a seekbar通过在屏幕上上下滚动而不使用搜索栏来调整屏幕亮度
【发布时间】:2014-05-07 03:50:41
【问题描述】:

是否可以通过简单地在屏幕上上下滑动来调整屏幕亮度,我应该使用哪种方法来获得它?

在搜索栏的帮助下我做到了,但很高兴知道如何使用滑动手势来完成它,因为它会对许多其他人有所帮助。

通过在搜索栏更改列表器上应用以下方法,可以轻松使用搜索栏调整屏幕亮度。

        public void onStopTrackingTouch(SeekBar seekBar)
        {
            System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness);
            LayoutParams layoutpars = window.getAttributes();
            layoutpars.screenBrightness = brightness / (float)255;
            window.setAttributes(layoutpars);
        }

        public void onStartTrackingTouch(SeekBar seekBar)
        {
            //Nothing handled here
        }

        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
        {
            if(progress<=20)
            {
                brightness=20;
            }
            else
            {
                brightness = progress;
            }
            float perc = (brightness /(float)255)*100;
            txtPerc.setText((int)perc +" %");
        }
    });   
}

有人知道不用搜索栏怎么做吗?

【问题讨论】:

  • 您不能获取视图的任何触摸事件并使用它来执行此操作吗?
  • 使用 ontouchEvent 我可以设置最小和最大亮度,但我无法获得中间值(亮度),我认为,onscroll 是这个答案的关键,但我不知道如何这样做,因为我是 android 的菜鸟。

标签: android brightness swipe-gesture onscrolllistener


【解决方案1】:

有点晚了,但是对于现在正在寻找它的人,您可以使用这个 android 库Swipper

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    • 1970-01-01
    相关资源
    最近更新 更多