SeekBar调节手机屏幕亮度
2017-02-28 13:08
337 查看
<1.惯例,来布局>
<2.源码>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <SeekBar android:id="@+id/seek_bar" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/showSeek" android:textSize="20.0sp" android:gravity="center"/> </LinearLayout>
<2.源码>
public class MainActivity extends AppCompatActivity { private SeekBar seekBar; private TextView showseek; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { update((float)seekBar.getProgress()/10); } }); } //实例化控件 private void init(){ seekBar= (SeekBar) findViewById(R.id.seek_bar); showseek= (TextView) findViewById(R.id.showSeek); //亮度是从0~1中的一个浮点数,由于getProess得到的是Int型,所以扩大10倍,赋值时除以10 seekBar.setMax(10); } private void update(float b){ //取得window属性保存在layoutParams中 WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.screenBrightness = b; getWindow().setAttributes(layoutParams); //显示修改后的亮度 layoutParams = getWindow().getAttributes(); showseek.setText("当前亮度:"+String.valueOf(layoutParams.screenBrightness)); } }
相关文章推荐
- 使用SeekBar组件调节屏幕亮度
- 使用SeekBar组件调节屏幕亮度
- android通过seekbar调节屏幕亮度
- Android——悬浮窗+侧边弹框+淡入淡出+背景shape+SeekBar调节手机亮度
- Android:用Seekbar来调节屏幕亮度
- 微信小程序例子——调节手机屏幕亮度
- Android之调节手机屏幕亮度
- 滑动调节音量与屏幕亮度
- 电脑屏幕亮度能否自动调节
- android调节屏幕亮度
- android调节屏幕亮度(包括只修改应用程序和修改系统)
- centos 调节屏幕亮度
- Win8系统中如何调节屏幕亮度
- 上下滑动可以调节屏幕亮度
- 【Android】系统音量及屏幕亮度调节
- Fedora18解决无线上网和屏幕亮度调节问题
- Android_调节屏幕亮度(背景灯)及保持背景灯常亮的方法
- 联想笔记本在Ubuntu16上无法调节屏幕亮度解决
- Mac 10.6.4 Snow 屏幕亮度调节方法 Toshiba M100
- win8系统中向日葵软件造成的屏幕亮度无法调节怎么办?