Four solutions for Android soft keyboard occlusion

Source: Internet
Author: User

    • Problem overview

When you enter content in the edit box, the soft keyboard pops up, and the screen area of the mobile phone often obscures the input interface, so let's look at the problem:

When entering user name and password, the system will pop up the keyboard, causing the system keyboard to block the text box problem:

Enter the password when the input box is blocked by the system keyboard, greatly reducing the user experience, this is the development of a very common soft keyboard occlusion problem, how to solve?

    • Simple solution

Method One

Write this code before setcontentview in your activity's oncreate.

GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Method Two

In the project's Androidmanifest.xml file interface corresponding to the <activity> added

This will make the screen move up the whole. If you add a android:windowsoftinputmode= "Adjustpan", the keyboard will overwrite the screen.

About Android:windowsoftinputmode

Activity main window and soft keyboard interaction mode, can be used to avoid Input Panel occlusion problem, after Android1.5 a new feature.

This genus affects two things:

"One" when the focus is generated, the soft keyboard is hidden or displayed

"Two" reduces the active main window size to make room for the soft keyboard

It must be set to a value in the list below, or a "state ..." value plus a combination of "adjust ..." values. Set multiple values in either group-multiple "state ..." values, such as &mdash, have undefined results. Each value is separated by |

For example:

<activityandroid:windowsoftinputmode= "Statevisible|adjustresize" ... >

The value set in this (except "stateunspecified" and "adjustunspecified") overrides the value set in the topic

Method Three

Replace the top layout with ScrollView, or add a layer of ScrollView to the top layout. This will roll the soft keyboard and the input box together, and the soft keyboard will always be at the bottom.

    • Code Controllability method

1. Main interface Layout file

2. Custom Linearlayoutview

This component can be implemented to hide and display certain areas based on the pop/close of the soft keyboard, which is the most critical part of the problem solving, with two main points:

① overriding onsizechanged methods

This method is the view life cycle method, which is called when the view size changes, such as vertical screen switching, soft keyboard popup. Here when the soft keyboard pops up causing the view dimension to change, it calls the Onsizechanged method, in which the core idea of implementing code is based on the size change, when the larger (soft keyboard pops up), some areas are hidden to give the editing interface enough space to display, when the recovery (soft keyboard off), And then show the hidden area.

② provides an implementation method of invoking an interface using a callback mechanism in the Keybordstatelistener interface.

3. Main interface Mainactivit

    • Achieve results

Keyboard popup:

Keyboard off:

Http://jingyan.baidu.com/article/86f4a73e77195e37d6526998.html

Four solutions for Android soft keyboard occlusion

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.