Customize dialog style activity in Android. Click the blank space to hide the soft keyboard function (dialog does not disappear)

1、 Demand trigger scenario:

The project needs to develop dialog display with EditText. When editing EditText, click the blank space of dialog to hide the soft keyboard. But dialog won't disappear. Examples are as follows:

2、 Implementation method:

When publishing requirements, I personally thought about directly creating a dialog through new. After many attempts, I couldn't meet the requirements, so I set the activity to dialog style for presentation and call methods to meet the requirements. The specific implementation is as follows:

The engineering structure of this demonstration example:

2.1androidmainfest.xml configuration file

You need to add a dialog theme to the activities that need to be displayed in the dialog style in the configuration file (you can call the system's own or customize the theme to add)

2.2 Java implementation code

(1) Baseactivity is the base class of activity in this demo. The code implementation is as follows:

(2) Mainactivity implementation code is as follows:

(3) The implementation code of main2activity as a dialog style activity is as follows:

The above is the custom dialog style activity in Android introduced by Xiaobian. Click the blank space to hide the soft keyboard function (dialog does not disappear). I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>