我正在制作一个计算器来学习Compose,所以我在屏幕上放置了自己的数字按钮,并希望防止软键盘出现。
这是我的repo:https://github.com/vitor-ramos/CalculadorCompose 我注意到在TextFieldImpl.kt中有一个修饰符用于显示键盘,所以我尝试克隆代码并删除了这一行:
我在这个问题中发现,使用视图可以扩展EditText并更改功能,但我没有找到Compose的等效方法:Android: 禁用所有EditText上的软键盘。
这是我的repo:https://github.com/vitor-ramos/CalculadorCompose 我注意到在TextFieldImpl.kt中有一个修饰符用于显示键盘,所以我尝试克隆代码并删除了这一行:
keyboardController.value?.showSoftwareKeyboard()
我知道复制代码不是一个好主意,但我想试一试,结果没成功。正如您在下面的原始代码中看到的那样,有一个TODO说它应该由BaseTextField处理,但是我查看了它的代码,没有找到它显示或隐藏键盘的位置。val textFieldModifier = modifier
.focusRequester(focusRequester)
.focusObserver { isFocused = it.isFocused }
.clickable(indication = null) {
focusRequester.requestFocus()
// TODO(b/163109449): Showing and hiding keyboard should be handled by BaseTextField.
// The requestFocus() call here should be enough to trigger the software keyboard.
// Investiate why this is needed here. If it is really needed, instead of doing
// this in the onClick callback, we should move this logic to the focusObserver
// so that it can show or hide the keyboard based on the focus state.
keyboardController.value?.showSoftwareKeyboard()
}
我在这个问题中发现,使用视图可以扩展EditText并更改功能,但我没有找到Compose的等效方法:Android: 禁用所有EditText上的软键盘。
public class NoImeEditText extends EditText {
public NoImeEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onCheckIsTextEditor() {
return false;
}
}
NoImeEditText
只是在自定义组合中使用@Composable
方法的问题,对吗? - Fred