Android 屏幕七彩闪动
来源:互联网 发布:js怎么判断分页 编辑:程序博客网 时间:2024/04/28 03:14
这是我第一次发博客,希望大家多多支持。
昨天一个朋友说,能不能用手机屏幕做手电筒,我就说把屏幕弄成白颜色,亮度调到最大就OK了。最后我在做的时候,感觉没什么技术含量,就稍微的扩展一下。让屏幕不听的闪动,实现了霓虹灯的功能。
不说了,直接上代码。
首先,在MainActivity中,加载自己创建的screen界面,并且将屏幕的亮度调大1f;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
private ScreenView screenView = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去掉标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
//去掉状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
screenView = new ScreenView(this);
setContentView(screenView);
//设置屏幕亮度 屏幕亮度为0~1f
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 1.0f;
getWindow().setAttributes(lp);
}
}
然后创建自己的View,继承View类并且实现Runnable接口
import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class ScreenView extends View implements Runnable {
private int index = 0;
//得到彩虹色数组
int[] colors = new int[] { Color.rgb(255, 0, 0), Color.rgb(255, 165, 0),
Color.rgb(255, 255, 0), Color.rgb(0, 255, 00),
Color.rgb(0, 127, 255), Color.rgb(0, 0, 255),
Color.rgb(139, 0, 255) };
public ScreenView(MainActivity mainActivity) {
super(mainActivity);
//启动线程
new Thread(this).start();
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//绘制界面
canvas.drawColor(colors[index]);
}
public void run() {
while (true) {
postInvalidate();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
index++;
if (index == 7) {
index = 0;
}
}
}
}
同时在XMl文件中部署自己的界面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.app
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
- Android 屏幕七彩闪动
- Android屏幕七彩闪动
- android文字闪动效果
- Android闪动的文字效果
- 关于绘图时屏幕闪动的问题
- android opengl es 七彩星星效果
- Android 七彩手电筒的实现与应用
- android制作闪动的红心
- 解决MFC屏幕闪动问题:双缓冲的实现(转)
- 解决MFC屏幕闪动问题:双缓冲的实现
- Android中如何实现图像的闪动
- android歌词滚动,不是闪动。怎样实现?
- 【Android学习】动态文字闪动效果
- Android键盘切换闪动原理及解决方案
- Android自定义View之闪动的TextView
- Android开启时标题栏会闪动
- android表情键盘完美解决闪动问题
- Android开发 之 LinearGradient与闪动文字效果
- C#解决UI主线程不响应
- nth_element 用法简介
- poj 3820 牡丹江区域赛 (树的直径+bfs)
- 想移植一个recovery
- php 与 html实现 订餐网页
- Android 屏幕七彩闪动
- JBox弹框插件应用实例代码
- Mac Yosemite 10.10 下利用 Launchctl 自启动 mysql
- hdu_3308 LCIS 区间合并 求最长递增子序列长度
- CSDN之金色十月线上编程比赛第二题:解密
- android自动化测试4-Robotium黑白盒测试
- 多线程用同一个dao对象就会存在多个线程执行同一方法,为什么不用考虑线程安全问题
- 第五章 Backbonejs中的View实践
- [笔记] 概率DP ZOJ-3822