View.VISIBLE 并且 INVISIBLE 在 Kotlin 中不起作用
View.VISIBLE and INVISIBLE doesn't work Kotlin
我有密码编辑文本和显示密码的按钮。只有当 edittext 不为空时,按钮才应该可见。我做了一些代码,但它不起作用(它总是不可见的)。这是代码:
passwordEditTextSUA.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (passwordEditTextSUA.text.toString() != "") {
showPasswordSUA.visibility == View.VISIBLE
} else {
showPasswordSUA.visibility == View.INVISIBLE
}
}
})
以及按钮和编辑文本的 xml:
<EditText
android:id="@+id/passwordEditTextSUA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="34dp"
android:layout_marginEnd="34dp"
android:layout_marginBottom="35dp"
android:hint="@string/enter_password"
android:inputType="textPassword"
android:theme="@style/EditTextTheme"
app:layout_constraintBottom_toTopOf="@+id/repeatPasswordEditTextSUA"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/showPasswordSUA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginBottom="1dp"
android:background="@android:color/transparent"
android:src="@drawable/button_show_password"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/passwordEditTextSUA"
app:layout_constraintEnd_toEndOf="@+id/passwordEditTextSUA"
app:layout_constraintTop_toTopOf="@+id/passwordEditTextSUA" />
怎么了?
将此 showPasswordSUA.visibility == View.VISIBLE
替换为 showPasswordSUA.visibility = View.VISIBLE
我使用 java,但我认为双等号的计算结果只是真或假。你只想使用一个 =
。见
我有密码编辑文本和显示密码的按钮。只有当 edittext 不为空时,按钮才应该可见。我做了一些代码,但它不起作用(它总是不可见的)。这是代码:
passwordEditTextSUA.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (passwordEditTextSUA.text.toString() != "") {
showPasswordSUA.visibility == View.VISIBLE
} else {
showPasswordSUA.visibility == View.INVISIBLE
}
}
})
以及按钮和编辑文本的 xml:
<EditText
android:id="@+id/passwordEditTextSUA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="34dp"
android:layout_marginEnd="34dp"
android:layout_marginBottom="35dp"
android:hint="@string/enter_password"
android:inputType="textPassword"
android:theme="@style/EditTextTheme"
app:layout_constraintBottom_toTopOf="@+id/repeatPasswordEditTextSUA"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="@+id/showPasswordSUA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginBottom="1dp"
android:background="@android:color/transparent"
android:src="@drawable/button_show_password"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@+id/passwordEditTextSUA"
app:layout_constraintEnd_toEndOf="@+id/passwordEditTextSUA"
app:layout_constraintTop_toTopOf="@+id/passwordEditTextSUA" />
怎么了?
将此 showPasswordSUA.visibility == View.VISIBLE
替换为 showPasswordSUA.visibility = View.VISIBLE
我使用 java,但我认为双等号的计算结果只是真或假。你只想使用一个 =
。见