zoukankan      html  css  js  c++  java
  • 控件:拖动条 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>




     

  • 相关阅读:
    全局索引 truncate有数据的分区,索引失效,没数据的分区,索引不失效
    数组的操作
    调存储过程shell
    Flex中的折线图
    SecurityError:Error #2048:安全沙箱冲突
    Flex中对表格中某列的值进行数字格式化并求百分比
    Flex中对表格中某列的值进行数字格式化
    ORA-00904:"T1"."AREA_ID" :标识符无效
    严重:IOException while loading persisted sessions:java.io.EOFException.
    开放的平台、向上的文化——揭秘万达电商(4)
  • 原文地址:https://www.cnblogs.com/androidsj/p/2379165.html
Copyright © 2011-2022 走看看