我正在尝试编写一个使用Samsung Pass和/或Google Auth的简单应用程序,但是尽管我的设备进行了适当的设置,但它们都不起作用。不显示用于保存密码和用户名的弹出窗口。使用Samsung Pass / Google Auth,其他应用程序可以在我的设备上正常运行。
在我的布局下面:
<LinearLayout 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:importantForAutofill="yes"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:autofillHints="username"
android:hint="username"
android:inputType="text"
android:importantForAutofill="yes" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:autofillHints="password"
android:hint="password"
android:importantForAutofill="yes"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Zaloguj"
app:layout_constraintTop_toBottomOf="@+id/password" />
</LinearLayout>
和活动:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
loginButton.setOnClickListener {
if (checkCredentials(username.text.toString(), password.text.toString())) {
val intent = Intent(this, LoggedInActivity::class.java)
startActivity(intent)
}
}
}
private fun checkCredentials(username: String, password: String): Boolean {
return (username.isNotEmpty() && password.isNotEmpty())
}
}
我在做什么错?
确定,找到原因-开始新活动后必须调用finish()。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
loginButton.setOnClickListener {
if (checkCredentials(username.text.toString(), password.text.toString())) {
val intent = Intent(this, LoggedInActivity::class.java)
startActivity(intent)
finish()
}
}
}