Android(安卓)设置亮度
16lz
2021-01-24
设置当前Activity中的亮度,退出Activity后恢复系统默认亮度。
未测试系统改变亮度后Activity亮度是否改变。
package com.ltc.screen;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.WindowManager;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class Actmain extends Activity {private TextView textView;private Button button;float f = 1.0f; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView)findViewById(R.id.textview); button = (Button)findViewById(R.id.btn); button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubf -= 0.1f;//f 不能 为0 ,为0就锁屏了。if(f < 0.0001f){f = 1.0f;}setBrightness(f);}}); } private void setBrightness(float f){ WindowManager.LayoutParams lp = getWindow().getAttributes();lp.screenBrightness = f; getWindow().setAttributes(lp); }}
更多相关文章
- [Android]单元测试实例
- android sdk api的层次结构
- android GMS认证之CTS测试命令详细
- Android(安卓)ListView实现方法一(ListActivity)
- Android(安卓)一键退出APP 实现
- Android(安卓)系统(264)---android进阶——自定义View
- 第十一篇 ANDROID 系统网络连接和管理机制
- Android系统信息获取 之二:版本信息获取
- Android(安卓)Crash:Bad notification for startForeground