优化数值选择器界面
This commit is contained in:
@@ -4,7 +4,6 @@ import android.app.AlertDialog
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.NumberPicker
|
import android.widget.NumberPicker
|
||||||
import android.widget.TextView
|
|
||||||
import com.google.android.material.button.MaterialButton
|
import com.google.android.material.button.MaterialButton
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
@@ -17,7 +16,6 @@ class NumberPickerDialog(context: Context) {
|
|||||||
private var numberPicker: NumberPicker? = null
|
private var numberPicker: NumberPicker? = null
|
||||||
private var editText: TextInputEditText? = null
|
private var editText: TextInputEditText? = null
|
||||||
private var inputLayout: TextInputLayout? = null
|
private var inputLayout: TextInputLayout? = null
|
||||||
private var tvRange: TextView? = null
|
|
||||||
private var maxValue: Int? = null
|
private var maxValue: Int? = null
|
||||||
private var minValue: Int? = null
|
private var minValue: Int? = null
|
||||||
private var value: Int? = null
|
private var value: Int? = null
|
||||||
@@ -63,7 +61,6 @@ class NumberPickerDialog(context: Context) {
|
|||||||
numberPicker = dialog.findViewById(R.id.number_picker)
|
numberPicker = dialog.findViewById(R.id.number_picker)
|
||||||
inputLayout = dialog.findViewById(R.id.til_input)
|
inputLayout = dialog.findViewById(R.id.til_input)
|
||||||
editText = dialog.findViewById(R.id.et_input)
|
editText = dialog.findViewById(R.id.et_input)
|
||||||
tvRange = dialog.findViewById(R.id.tv_range)
|
|
||||||
val btnSwitch = dialog.findViewById<MaterialButton>(R.id.btn_switch_input)
|
val btnSwitch = dialog.findViewById<MaterialButton>(R.id.btn_switch_input)
|
||||||
|
|
||||||
numberPicker?.let { np ->
|
numberPicker?.let { np ->
|
||||||
@@ -71,20 +68,23 @@ class NumberPickerDialog(context: Context) {
|
|||||||
maxValue?.let { np.maxValue = it }
|
maxValue?.let { np.maxValue = it }
|
||||||
value?.let { np.value = it }
|
value?.let { np.value = it }
|
||||||
}
|
}
|
||||||
tvRange?.text = "输入范围: ${numberPicker?.minValue} - ${numberPicker?.maxValue}"
|
|
||||||
|
|
||||||
btnSwitch?.setOnClickListener {
|
btnSwitch?.setOnClickListener {
|
||||||
useInputMode = !useInputMode
|
useInputMode = !useInputMode
|
||||||
if (useInputMode) {
|
if (useInputMode) {
|
||||||
numberPicker?.visibility = View.GONE
|
numberPicker?.visibility = View.GONE
|
||||||
inputLayout?.visibility = View.VISIBLE
|
inputLayout?.visibility = View.VISIBLE
|
||||||
tvRange?.visibility = View.VISIBLE
|
|
||||||
|
val min = minValue ?: numberPicker?.minValue
|
||||||
|
val max = maxValue ?: numberPicker?.maxValue
|
||||||
|
inputLayout?.hint = "输入范围: $min - $max"
|
||||||
|
|
||||||
editText?.setText(numberPicker?.value?.toString() ?: value?.toString())
|
editText?.setText(numberPicker?.value?.toString() ?: value?.toString())
|
||||||
} else {
|
} else {
|
||||||
numberPicker?.visibility = View.VISIBLE
|
numberPicker?.visibility = View.VISIBLE
|
||||||
inputLayout?.visibility = View.GONE
|
inputLayout?.visibility = View.GONE
|
||||||
tvRange?.visibility = View.GONE
|
|
||||||
inputLayout?.error = null
|
inputLayout?.error = null
|
||||||
|
inputLayout?.hint = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,11 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_range"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/til_input"
|
|
||||||
app:layout_constraintStart_toStartOf="@id/til_input"/>
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/til_input"
|
android:id="@+id/til_input"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/Widget.Material3.TextInputLayout.FilledBox.Dense"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user