• 控件:拖动条 SeekBar(改变屏幕亮度)


    View Code
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent">
    <ImageView
    android:id="@+id/pic"
    android:src
    ="@drawable/android_book"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"/>
    <SeekBar
    android:id="@+id/seekbar"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content" />
    </LinearLayout>
    View Code
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.WindowManager;
    import android.widget.SeekBar;

    public class MySeekBarDemo extends Activity {
    private SeekBar seekbar = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.main);
    this.seekbar = (SeekBar) super.findViewById(R.id.seekbar);
    this.seekbar.setMax(100);
    this.seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImpl());
    }

    private class OnSeekBarChangeListenerImpl implements SeekBar.OnSeekBarChangeListener {
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
    MySeekBarDemo.this.setScreenBrightness((float) seekBar.getProgress() / 100);
    }
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }
    }
    /**
    * WindowManager.LayoutParams可以进行屏幕亮度调节
    *
    @param num
    */
    private void setScreenBrightness(float num) { // 0 ~ 1表示亮度
    // 取得屏幕的属性
    WindowManager.LayoutParams layoutParams = super.getWindow().getAttributes() ;
    // 设置屏幕亮度
    layoutParams.screenBrightness = num ;
    // 重新设置窗口的属性
    super.getWindow().setAttributes(layoutParams) ;
    }
    }
    View Code
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package
    ="org.lxh.demo"
    android:versionCode
    ="1"
    android:versionName
    ="1.0">
    <uses-sdk android:minSdkVersion="3" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">

    <activity android:name=".MySeekBarDemo"
    android:label
    ="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    </application>
    </manifest>




     

  • 相关阅读:
    Django框架基础之分页
    Django框架基础之session
    Django框架基础之COOKIE
    Django框架基础(二)
    linux挂载/卸载windows共享文件夹
    std::string 字符串操作(分割,去空格)
    Ubuntu sudo不用输入密码的方法
    Qt学习
    ubuntu上利用 checkinstall/dpkg 制作/安装/卸载deb或rpm包
    wxWidgets编译安装
  • 原文地址:https://www.cnblogs.com/androidsj/p/2379165.html
Copyright © 2020-2023  润新知