EditText: how to enable/disable input?(EditText:如何启用/禁用输入?)
问题描述
我有一个 7x6 网格的 EditText 视图.我希望在应用程序启动时将它们全部禁用,即它们的行为应该像普通的 TextViews 并且不可编辑.然后用户点击网格中的一个单元格,它会更改其背景并执行一些视觉操作.如果用户再次单击单元格,它应该允许编辑.我正在努力使用 OnClick() 和 OnFocusChange() 监听器,但我无法完成这样的基本交互.
I have a 7x6 grid of EditText views. I want all of them disabled when the application starts, ie they should behave like normal TextViews and not to be editable. Then the user taps one cell in the grid, it changes its background and performs something visual. If the user clicks on the cell one more time it should allow editing. I'm struggling with OnClick() and OnFocusChange() listeners, but I can't accomplish such a basic interaction.
使用 setEnabled() 和 setFocusable() 没有帮助.我想知道为什么即使像这样简单的任务在 Android 上也变得如此困难
Playing with setEnabled() and setFocusable() doesn't help. I wonder why even a simple task like this has been made so difficult on Android
推荐答案
我终于找到了解决方案.这是一个调用的问题
I finally found a solution. It's a matter of calling
setFocusableInTouchMode(boolean)setFocusable(boolean)
当 EditText 第一次创建时,它可以拦截点击.然后可以再次设置这些标志以使 EditText 可编辑,请求焦点,并使用 InputMethodManager 方法手动显示/隐藏软键盘
when the EditText is first created, so it can intercept the clicks. Then one can set those flags back again to make the EditText editable, request the focus, and manually show/hide the soft keyboard with InputMethodManager methods
这篇关于EditText:如何启用/禁用输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EditText:如何启用/禁用输入?
基础教程推荐
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
