最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android studio編寫簡(jiǎn)單的手電筒APP

 更新時(shí)間:2016年08月03日 14:38:34   作者:知無(wú)涯者  
一個(gè)簡(jiǎn)單的APP控制的手電筒代碼,android studio編寫一個(gè)手電筒app,調(diào)用手機(jī)的閃光等實(shí)現(xiàn)手電筒的功能,感興趣的小伙伴們可以參考一下

很不錯(cuò)的手電筒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("關(guān)");
      } else {
        parameters = camera.getParameters();
        parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
        camera.setParameters(parameters);
        islight = true;
        button.setText("開(kāi)");
      }
     }
 
   });
  }
}

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("關(guān)");
      } else {
        parameters = camera.getParameters();
        parameters.setFlashMode(Parameters.FLASH_MODE_OFF);
        camera.setParameters(parameters);
        islight = true;
        button.setText("開(kāi)");
      }
     }
 
   });
  }
}

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="關(guān)"
    android:textOn="開(kāi)"
    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>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

罗甸县| 丰宁| 鹤山市| 中江县| 贡山| 滨海县| 临清市| 宣恩县| 沅陵县| 邹城市| 石渠县| 吉木乃县| 苍南县| 兰西县| 龙胜| 兴文县| 桐城市| 大厂| 泗阳县| 兰坪| 重庆市| 沙坪坝区| 曲沃县| 花垣县| 瑞丽市| 九龙城区| 雷波县| 梅州市| 穆棱市| 湖州市| 社会| 偏关县| 平陆县| 蓬莱市| 偃师市| 明光市| 长兴县| 合水县| 天峨县| 嘉鱼县| 柳河县|