自己写的一个android小应用 手电筒
16lz
2021-01-24
简洁 小巧 免费 无广告
代码奉上
active类
1 private boolean isopent = false; 2 3 private Camera camera; 4 5 @Override 6 protected void onCreate(Bundle savedInstanceState) { 7 8 // TODO Auto-generated method stub 9 10 super.onCreate(savedInstanceState);11 12 View view = View.inflate(this, R.layout.activity_main, null);13 14 setContentView(view);15 16 final RelativeLayout layout_main = (RelativeLayout) findViewById(R.id.mainactive);17 final ImageView img_but = (ImageView) findViewById(R.id.main_img);18 19 img_but.setOnClickListener(new View.OnClickListener() {20 21 @Override22 public void onClick(View v) {23 24 if (!isopent) {25 layout_main.setBackgroundColor(Color.parseColor("#FFFFFF"));26 img_but.setBackgroundColor(Color.parseColor("#FFFFFF"));27 28 camera = Camera.open();29 30 Parameters params = camera.getParameters();31 32 params.setFlashMode(Parameters.FLASH_MODE_TORCH);33 34 camera.setParameters(params);35 36 camera.startPreview(); // 开始亮灯37 38 isopent = true;39 40 } else {41 42 layout_main.setBackgroundColor(Color.parseColor("#000000"));43 img_but.setBackgroundColor(Color.parseColor("#000000"));44 45 camera.stopPreview(); // 关掉亮灯46 47 camera.release(); // 关掉照相机48 49 isopent = false;50 }51 }52 });53 54 }55 56 private long exitTime = 0;57 58 @Override59 public boolean onKeyDown(int keyCode, KeyEvent event) {
layout
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:id="@+id/mainactive" 4 android:layout_width="fill_parent" 5 android:layout_height="fill_parent" 6 android:background="#000000" 7 tools:context=".MainActivity" > 8 9 <ImageView10 android:id="@+id/main_img"11 android:layout_width="128dip"12 android:layout_height="128dip"13 android:src="@drawable/light"14 android:layout_centerInParent="true"15 android:background="#000000" />16 17 </RelativeLayout>
下载地址:http://url.cn/OpGm12
BTS工作室
更多相关文章
- android代码库之执行Shell命令或者脚本
- 在android中如何在代码中设置textview的属性和效果
- Androd学习笔记——Android(安卓)Camera Parameters分析
- 编译Android(安卓)2.3.1 源代码心得
- Android(安卓)获取git 版本号
- android studio基础教程:3.美化按钮
- gRPC请求中对header进行处理
- Android(安卓)获取包名,版本信息及VersionName名称
- android p状态栏,插入sim卡,关闭数据流量,状态栏卡图标右下角有X图标