如何调整屏幕颜色亮度?

时间:2015-08-19 06:10:45

标签: android colors screen

我正在尝试创建一个屏幕过滤器应用程序。

所以我正在寻找一种改变屏幕颜色的方法。

寻找很多网站,很难找到我认为的方式。

首先,如何获得对系统的访问权限,但不适合分发。

我认为第二种替换或覆盖颜色的方法,并不容易。

有很多页面介绍该应用程序。

布局已创建。

现在找到办法。

我只是看不到页面?

1 个答案:

答案 0 :(得分:0)

更改屏幕亮度的Android权限

          .
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

activity_main.xml中

<RelativeLayout 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"
tools:context=".MainActivity" >

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="26dp"
    android:max="10" />
    </RelativeLayout>

MainActivity.java

  package com.example.android_adjustbrightness;
  import android.os.Bundle;
  import android.provider.Settings.SettingNotFoundException;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.SeekBar;
  import android.widget.SeekBar.OnSeekBarChangeListener;

  public class MainActivity extends Activity {

  private SeekBar seekBar;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 seekBar = (SeekBar) findViewById(R.id.seekBar1);
 seekBar.setMax(255);

 float curBrightnessValue = 0;
 try {
 curBrightnessValue = android.provider.Settings.System.getInt(
 getContentResolver(),
 android.provider.Settings.System.SCREEN_BRIGHTNESS);
 } catch (SettingNotFoundException e) {
  e.printStackTrace();
  }

 int screen_brightness = (int) curBrightnessValue;
 seekBar.setProgress(screen_brightness);
 seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
 int progress = 0;

@Override
 public void onProgressChanged(SeekBar seekBar, int progresValue,
 boolean fromUser) {
  progress = progresValue;
}

@Override
 public void onStartTrackingTouch(SeekBar seekBar) {
 // Do something here,
 // if you want to do anything at the start of
 // touching the seekbar
 }

@Override
 public void onStopTrackingTouch(SeekBar seekBar) {
 android.provider.Settings.System.putInt(getContentResolver(),
  android.provider.Settings.System.SCREEN_BRIGHTNESS,
  progress);
 }
 });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }

 }

的AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android_adjustbrightness"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.WRITE_SETTINGS" >
</uses-permission>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.android_adjustbrightness.MainActivity"
        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>