плавная прокрутка в EditText < /h2>
< />
Код: Выделить всё
class TodoInputDialogFragment : BottomSheetDialogFragment() {
private var _binding: TodoInputDialogFragmentBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
private var keyboardVisible = false
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = TodoInputDialogFragmentBinding.inflate(inflater, container, false)
val root: View = binding.root
// https://stackoverflow.com/questions/64947700/how-to-adjust-dialog-layout-when-soft-keyboard-appears-using-the-latest-windowin
ViewCompat.setOnApplyWindowInsetsListener(root) { _, insets ->
// https://stackoverflow.com/a/63595830/72437
val currKeyboardVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
if (!currKeyboardVisible && (this.keyboardVisible != currKeyboardVisible)) {
dismiss()
}
this.keyboardVisible = currKeyboardVisible
insets
}
binding.submitButton.setOnClickListener {
submit()
}
return root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
focusAndShowKeyboard(requireActivity(), binding.editText)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
// https://stackoverflow.com/questions/64947700/how-to-adjust-dialog-layout-when-soft-keyboard-appears-using-the-latest-windowin
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
dialog.window?.also {
it.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
}
}
// https://stackoverflow.com/questions/46861306/how-to-disable-bottomsheetdialogfragment-dragging
dialog.setOnShowListener { dialogInterface ->
val bottomSheet = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet)
if (bottomSheet != null) {
val behavior: BottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
behavior.isDraggable = false
}
}
return dialog
}
override fun getTheme(): Int {
return com.xxx.R.style.TodoInputDialogFragmentStyle
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun submit() {
}
}
< /code>
styles.xml
@style/BottomSheet_Rounded
adjustResize
false
< /code>
todo_input_dialog_fragment.xml
< /code>
Однако я изо всех сил пытаюсь достичь гладкого эффекта прокрутки в EditText. Несмотря на то, что пробовал несколько методов, прокрутка остается нервной и не отвечает. Есть ли у кого -нибудь предложения о том, как это решить?BottomSheetDialogFragment
Я пробую другую реализацию, используя диагфрагмент с помощью EDTText
dialog_custom.xml
< /code>
LAGGY Scrolling в EditText (DialogFragment[/code])
У вас есть идея, почему это так? Почему определенные приложения могут достичь плавной прокрутки в EditText , когда они используют его с помощью BottomSheetDialogFragment или DialogFragment ?
Подробнее здесь: https://stackoverflow.com/questions/783 ... t-dialogfr