1. 程式人生 > 其它 >php短視訊原始碼,SeekBar進度條滑動調節螢幕亮度

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進度條滑動調節螢幕亮度實現的相關程式碼, 更多內容歡迎關注之後的文章