How to Make Flashlight App in Android Studio
How to Make Flashlight App in Android Studio Here are the flashlight android app codeĀ Step 1 Create a new project in Android Studio and name it “FlashlightApp”. Open the activity_main.xml file located in the res/layout directory. Replace the existing code with the following XML layout:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<?xml version="1.0" encoding="utf-8"?> <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"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <ImageView android:id="@+id/flashlightImage" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/ic_flashlight_off" /> <Button android:id="@+id/toggleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Toggle Flashlight" android:textColor="#FFFFFF" android:background="#FF4081" android:padding="8dp" android:layout_marginTop="24dp" android:onClick="toggleFlashlight" /> </LinearLayout> </RelativeLayout> |
Step 2 Open the MainActivity.java file located in … Read more