MyDemo.java
package com.jackie.seekbarproject;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MyDemo extends Activity {
private SeekBar seekBar = null;
@Override
protected 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 OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
MyDemo.this.setScreenBrightness((float)seekBar.getProgress()/100);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*MyDemo.this.show.append("*** 开始拖动,当前值:"+seekBar.getProgress()+"\n" );
*/
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*MyDemo.this.show.append("*** 停止拖动,当前值:"+seekBar.getProgress()+"\n" );*/
}
}
private void setScreenBrightness(float num){
WindowManager.LayoutParams layoutParams=getWindow().getAttributes();
layoutParams.buttonBrightness=num;//num为0到1之间的浮点数
super.getWindow().setAttributes(layoutParams);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_demo, menu);
return true;
}
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MyDemo extends Activity {
private SeekBar seekBar = null;
@Override
protected 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 OnSeekBarChangeListener {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
MyDemo.this.setScreenBrightness((float)seekBar.getProgress()/100);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*MyDemo.this.show.append("*** 开始拖动,当前值:"+seekBar.getProgress()+"\n" );
*/
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*MyDemo.this.show.append("*** 停止拖动,当前值:"+seekBar.getProgress()+"\n" );*/
}
}
private void setScreenBrightness(float num){
WindowManager.LayoutParams layoutParams=getWindow().getAttributes();
layoutParams.buttonBrightness=num;//num为0到1之间的浮点数
super.getWindow().setAttributes(layoutParams);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_demo, menu);
return true;
}
Main.xml
<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"
tools:context=".MyDemo" >
<ImageView
android:id="@+id/pic"
android:src="@drawable/pic_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MyDemo" >
<ImageView
android:id="@+id/pic"
android:src="@drawable/pic_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>