Selasa, 03 Februari 2026

langkah langkah membuat login di android studio untuk aplikasi to do list

 

1. Buat Project Baru

Pilih:

  • Empty Views Activity

  • Language: Kotlin


✅ 2. Buat Activity

Buat 2 activity:

  1. LoginActivity

  2. DashboardActivity

Buat 2 kt:

  1. LoginActivity.kt

  2. activity_dashboard.xml



✅ 3. Layout activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="24dp">

<TextView
android:text="Login"
android:textSize="24sp"
android:textStyle="bold"
android:layout_marginBottom="24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<EditText
android:id="@+id/edtUsername"
android:hint="Username"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<EditText
android:id="@+id/edtPassword"
android:hint="Password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"/>

<Button
android:id="@+id/btnLogin"
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"/>
</LinearLayout>

✅ 4. LoginActivity.kt

package com.example.todolist

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class LoginActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)

val edtUsername = findViewById<EditText>(R.id.edtUsername)
val edtPassword = findViewById<EditText>(R.id.edtPassword)
val btnLogin = findViewById<Button>(R.id.btnLogin)

btnLogin.setOnClickListener {
val username = edtUsername.text.toString()
val password = edtPassword.text.toString()

if (username == "admin" && password == "123") {
Toast.makeText(this, "Login Berhasil", Toast.LENGTH_SHORT).show()
val intent = Intent(this, DashboardActivity::class.java)
startActivity(intent)
finish()
} else {
Toast.makeText(this, "Username atau Password salah!", Toast.LENGTH_SHORT).show()
}
}
}
}

✅ 5. Layout activity_dashboard.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<TextView
android:text="Dashboard To Do List"
android:textSize="22sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>

✅ 6. DashboardActivity.kt

package com.example.todolist


import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class DashboardActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dashboard)
}
}

✅ 7. Set Login Sebagai Halaman Awal

Di AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Todolist">
<activity
android:name=".DashboardActivity"
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


Tidak ada komentar:

Posting Komentar

MANAJEMEN BASIS DATA (BACKUP)

MATERI: MANAJEMEN BASIS DATA (BACKUP) 🎯 Tujuan Pembelajaran Peserta didik mampu: Memahami konsep backup database Menjelaska...