So far I have done:
MainActivity:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val email: EditText = this.findViewById(R.id.edt_mail)
val pass: EditText = this.findViewById(R.id.edt_password)
val scrollView = findViewById<View>(R.id.nestedScrollView) as ScrollView
email.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
scrollView.postDelayed({
scrollView.fullScroll(View.FOCUS_DOWN)
}, 1200)
}
}
pass.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
scrollView.postDelayed({
scrollView.fullScroll(View.FOCUS_DOWN)
}, 1200)
}
}}}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.constraint.ConstraintLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logo"
android:layout_width="258dp"
android:layout_height="47dp"
android:layout_marginTop="164dp"
android:contentDescription="@string/companyLogo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.515"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<TextView
android:id="@+id/LoginGuideLine"
style="@style/LoginGuideLine"
android:layout_width="295dp"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:padding="20dp"
android:text="@string/LoginGuideLine"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.518"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo" />
<android.support.design.widget.TextInputLayout
android:id="@+id/edtl_login"
style="@style/TextInput"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.518"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/LoginGuideLine">
<android.support.design.widget.TextInputEditText
android:id="@+id/edt_mail"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/EmailHint"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/edtl_password"
style="@style/TextInput"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.518"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edtl_login">
<android.support.design.widget.TextInputEditText
android:id="@+id/edt_password"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="@string/PasswordHint"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/LoginBtn"
style="@style/PrimaryBtn"
android:layout_width="295dp"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:text="@string/BtnTxt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.518"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edtl_password" />
</android.support.constraint.ConstraintLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="constraints">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
This is basically a Login Page UI that I am making where I want to the screen to scroll down automatically when focused on either email or password field. On email field, it does the job but on the password field, it shifts the focus automatically back to Email field and I have tried to reset the focus but that doesn't seem to work as well so I am not sure where the issue is.