Dola TENG 1 рік тому
батько
коміт
365c25ea97

+ 25 - 0
app/src/main/java/com/sambath/sbc/screen/register/RegisterActivity.kt

@@ -1,10 +1,13 @@
 package com.sambath.sbc.screen.register
 
+import android.content.Intent
 import androidx.appcompat.app.AppCompatActivity
 import android.os.Bundle
+import android.view.MenuItem
 import android.view.View
 import android.widget.ArrayAdapter
 import com.sambath.sbc.R
+import com.sambath.sbc.screen.login.LoginActivity
 import kotlinx.android.synthetic.main.activity_register.et_gender
 import kotlinx.android.synthetic.main.activity_register.radioButtonEmail
 import kotlinx.android.synthetic.main.activity_register.radioButtonPhone
@@ -16,6 +19,7 @@ class RegisterActivity : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_register)
+        supportActionBar?.setDisplayHomeAsUpEnabled(true)
 
         val spinnerData = listOf("Select Gender", "Female", "Male", "Other")
         val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, spinnerData)
@@ -26,6 +30,27 @@ class RegisterActivity : AppCompatActivity() {
         setGender()
     }
 
+    override fun onOptionsItemSelected(item: MenuItem): Boolean {
+        when (item.itemId) {
+            android.R.id.home -> {
+                onBackPressed() // Navigate back when the back button (up button) is pressed
+                return true
+            }
+            else -> return super.onOptionsItemSelected(item)
+        }
+    }
+
+    override fun onBackPressed() {
+        super.onBackPressed()
+
+        // Start the LoginActivity
+        val intent = Intent(this, LoginActivity::class.java)
+        startActivity(intent)
+
+        // Finish the RegisterActivity to prevent it from going back to the RegisterActivity
+        finish()
+    }
+
     private fun setGender() {
         if (radioGroup.checkedRadioButtonId == R.id.radioButtonEmail) {
             til_email.visibility = View.VISIBLE

+ 1 - 1
app/src/main/res/values/strings.xml

@@ -61,7 +61,7 @@
     <string name="action_channel_4">CH4</string>
     <string name="type">"ប្រភេទ: "</string>
     <string name="btn_forgot">Forgot Password?</string>
-    <string name="btn_signup">Sign Up\n</string>
+    <string name="btn_signup">Sign Up</string>
     <string name="hint_firstname">First Name</string>
     <string name="hint_lastname">Last Name</string>
     <string name="hint_gender">Gender</string>