Android Alertdialog add EditText but do not eject soft keyboard and other issues such as the resolution and reasons

Source: Internet
Author: User

abstract : Alertdialog add edittext but do not eject soft keyboard and other issues on the internet there are many solutions,

This article is intended to give a more effective solution, and to explore its causes

Body

Inserting a text box in a dialog box is a very common requirement

Typically we choose to create EditText objects in code

At this point, you need to set the input properties for EditText in your code.

However, it is often found that the set properties do not work or even eject the soft keyboard (although the physical keyboard can be entered)

There are a number of solutions to the problem, and here is a more common way to do this:

Inputpassedittext.setinputtype (inputtype.type_class_text| INPUTTYPE.XXX);

is the bitwise or previous inputtype when setting the input type. Type_class_text

It is 0x80 in the 16 binary.

For example, a Password Entry dialog box can be written like this

New  Alertdialog.builder (mainactivity.  this); Final New EditText (mainactivity.  this); Builder.setview (Inputpassedittext);

// The input box is a cipher-style Inputpassedittext.setinputtype (inputtype.type_class_text| Inputtype.type_text_variation_password);

This not only solves the problem that the soft keyboard does not eject, but also obtains the expected input effect.

Problem solving.

========================= gorgeous split line, below more exciting ===================================

Actually, InputType is a class in Android.

Android.text.InputType

There is no method for this class, only dozens of static constants

Type_class_text is one of the most commonly used

The constants that start with Type_class have these four kinds

int Type_class_datetime

int Type_class_number

int Type_class_phone

int Type_class_text


Examples examples of their usage

A password field with with and the password visible to the User: (Visual password input area)
InputType = Type_class_text | Type_text_variation_visible_password
A multi-line postal address with automatic capitalization: (Multi-line input in postal format)
InputType = Type_class_text | type_text_variation_postal_address | Type_text_flag_multi_line
A Time field: (Input times)
InputType = Type_class_datetime | Type_datetime_variation_time

Google's API exposes us to the use of a bitwise OR of the class and flag to achieve the desired effect (Google has carefully designed 2 binary bits per constant)

Here I give two common examples:

Enter a digital password

Inputpassedittext.setinputtype (inputtype.type_class_number| Inputtype.type_number_variation_password);

Enter the digital plaintext:

Inputpassedittext.setinputtype (inputtype.type_class_number| Inputtype.type_number_variation_normal);

There are many specific uses, not listed here, interested readers can go through the Goole official documents.

Android Alertdialog add EditText but do not eject soft keyboard and other issues such as the resolution and reasons

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.