4

After looking up various questions on stack overflow, I have found that many other people had the following problems:

  1. Background gets resized when soft keyboard opens
  2. Soft keyboard opens when activity starts

The solution to both of these lies in the ActivityManifest.xml.

To prevent the background image from being resized when the soft keyboard opens, you can add android:windowSoftInputMode="stateVisible|adjustPan" to the <activity> in the manifest.

To prevent the soft keyboard opening when the activity starts, you can add android:windowSoftInputMode="stateHidden" to the <activity> in the manifest.

The fact that one solution requires stateHidden and the other requires stateVisible means that I cannot use both solutions. I am looking to prevent the soft keyboard from stealing focus on activity start but also prevent the soft keyboard from resizing the background when the user does decide to focus on the EditText.

Is there a viable solution to both of these issues?

Mike Baxter
  • 6,868
  • 17
  • 67
  • 115

4 Answers4

0

If your EditText is wrapped within a parent container, set android:focusableInTouchMode="true" for that container. Basically, make that container receive the initial focus when the activity starts. Take a look at this link

Community
  • 1
  • 1
Vino
  • 1,544
  • 1
  • 18
  • 26
  • I've seen this solution elsewhere before, but it didn't actually work for me. I'm looking for something a little less hacky really. – Mike Baxter Mar 13 '14 at 09:16
0

The fact that one solution requires stateHidden and the other requires stateVisible means that I cannot use both solutions.

Yes. But, you can use stateHidden|adjustPan.

Keyboard will not pop up unless user clicks on an EditText. And potential changes to your background will be in terms of positioning; scaling of the background will not occur.

Vikram
  • 51,313
  • 11
  • 93
  • 122
0

Is any part of your layout a scrollable container (like ListView)? If so, try setting android:isScrollContainer="false" on that item in your XML layout.

If you have any views which have android:isScrollContainer="true", the layout manager will attempt to resize your layout when the keyboard pops up, regardless of `android:windowSoftInputMode'.

Here's a similar question: What does android:isScrollContainer do?

Community
  • 1
  • 1
Josh
  • 10,618
  • 2
  • 32
  • 36
0

There are basically two ways to fulfill your requirement.

  • Just use the below activity tag

    android:windowSoftInputMode="adjustPan|stateAlwaysHidden"

    Or

  • Using android:windowSoftInputMode="stateVisible|adjustPan" to the activity tag in the manifest.

Now with your EditText use following android:focusableInTouchMode="true" with android:focusable="false".

Arpit Garg
  • 8,476
  • 6
  • 34
  • 59