Detailed explanation of how Android prohibits inputting content into EditText control

preface

EditText control is often encountered in Android development, and in the process of app development, such a problem is encountered, that is, how can Android EditText control prohibit inputting content into it?

At the beginning, I found a solution to the modified version, but there was a problem when I wanted to input it. I can refer to it, but it is not recommended to write it like this

You may be a little surprised to see this problem. The function of EditText is to write content to it? Moreover, if you really want to prohibit the input of text, add it in the layout file

Or is it OK to use it in the code?

The project requirements are like this, followed by an EditText Check@R_ 270_ 2419 @, check Check@R_ 270_ 2419 @ can be input, otherwise it can't be input. In addition, there are such requirements. For example, if the content has been settext(), it needs to be prohibited from input to prevent it from being modified

If no content is displayed, set EditText to an inputable state

After testing and verification, the effect of setfocusable method is only effective when used for the first time, that is, if it is set in the layout file:

Even if you set this control property in the code: EditText. Setfocusable (true); It cannot be edited, that is, the setfocusable scheme is not feasible. After exploration, a feasible scheme is realized by setinputtype. The code is as follows

The application is turned on by default. Special note: this method can only prohibit the soft keyboard. If the mobile phone comes with a hard keyboard, this scheme will fail

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>