php短视频源码,SeekBar进度条滑动调节屏幕亮度

php短视频源码,SeekBar进度条滑动调节屏幕亮度实现的相关代码
1.布局文件

```cpp
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<SeekBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/shape_circle"

/>
</LinearLayout>
```

 

2:布局文件所需的po_seekbar和shape_circle
po_seekbar文件

```cpp
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@android:id/background">
<shape>
<solid android:color="#C9CAC5" />
<corners android:radius="10dip"/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="10dip"/>
<solid android:color="#C9CAC5" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="10dip"/>
<solid android:color="#FF5722" />
</shape>
</clip>
</item>

</layer-list>
```

 

shape_circle文件

```cpp
<?xml version="1.0" encoding="utf-8"?>
<!--seekbar的滑动块样式-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!--solid表示远的填充色-->
<solid android:color="#484848"></solid>
<!--stroke代表远的边框线-->
<stroke android:color="#484848"
android:width="1dp"
></stroke>
<!--size控制高宽-->

<size
android:width="24dp"
android:height="24dp"></size>
</shape>
```

 

3:主代码

```cpp
public class MainActivity extends AppCompatActivity {
//声明拖动条
private SeekBar seekBar;
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textview);
seekBar = (SeekBar) findViewById(R.id.progress);

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//当滑动条的位置发生改变时,触发该方法,在这里直接调用参数progress,即当前滑块代表的进度值
textView.setText("Value" + Integer.toString(progress));
MainActivity.this.setScreenBrightness((float) seekBar.getProgress() / 100);
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
}

private void setScreenBrightness(float num) {
//取得屏幕的属性
WindowManager.LayoutParams layoutParams = super.getWindow().getAttributes();
//设置屏幕的亮度
layoutParams.screenBrightness = num;
//重新设置窗口的属性
super.getWindow().setAttributes(layoutParams);
}

}
```

 


以上就是php短视频源码,SeekBar进度条滑动调节屏幕亮度实现的相关代码, 更多内容欢迎关注之后的文章

posted @ 2021-08-05 14:19  云豹科技-苏凌霄  阅读(58)  评论(0编辑  收藏  举报