很不错的手电筒APP,分享给大家,希望大家喜欢。
1. Java代码
package com.example.goo.gfire; import androID.app.Activity;import androID.harDWare.Camera;import androID.harDWare.Camera.Parameters;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button; public class FireActivity extends Activity { private button button; private Camera camera = Camera.open(); private Parameters parameters; private boolean islight=true; public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_fire); button = (button) this.findVIEwByID(R.ID.bn); button.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (islight) { camera.startPrevIEw(); parameters = camera.getParameters(); parameters.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(parameters); islight = false ; button.setText("关"); } else { parameters = camera.getParameters(); parameters.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(parameters); islight = true; button.setText("开"); } } }); }}
2. FireActivity.java
package com.example.goo.gfire; import androID.app.Activity;import androID.harDWare.Camera;import androID.harDWare.Camera.Parameters;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button; public class FireActivity extends Activity { private button button; private Camera camera = Camera.open(); private Parameters parameters; private boolean islight=true; public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_fire); button = (button) this.findVIEwByID(R.ID.bn); button.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (islight) { camera.startPrevIEw(); parameters = camera.getParameters(); parameters.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(parameters); islight = false ; button.setText("关"); } else { parameters = camera.getParameters(); parameters.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(parameters); islight = true; button.setText("开"); } } }); }}
3. content_fire.xml
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:paddingBottom="@dimen/activity_vertical_margin" androID:paddingleft="@dimen/activity_horizontal_margin" androID:paddingRight="@dimen/activity_horizontal_margin" androID:paddingtop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_vIEw_behavior" tools:context="com.example.goo.gfire.FireActivity" tools:showIn="@layout/activity_fire"> <TextVIEw androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:text="电筒模式" androID:textSize="34sp" androID:textStyle="bold" androID:gravity="center"/> <button androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ID="@+ID/bn" androID:textOff="关" androID:textOn="开" androID:height="400dp" androID:layout_alignParentBottom="true" androID:layout_centerHorizontal="true" androID:layout_marginBottom="59dp" androID:FontFeaturesettings="@string/auth_Google_play_services_clIEnt_facebook_display_name" androID:textcolor="@color/common_signin_btn_dark_text_focused" androID:textStyle="bold" androID:textSize="100sp" /> </relativeLayout>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。
总结以上是内存溢出为你收集整理的Android studio编写简单的手电筒APP全部内容,希望文章能够帮你解决Android studio编写简单的手电筒APP所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)