I am working on a game and I want an EditText position above the soft keyboard when it pops up.
Here is what my code looks like when I build the View Hierarchy in my Main Activity:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
viewGroup = new RelativeLayout(this);
viewGroup.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
view = new GameView(this);
RelativeLayout.LayoutParams vLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
vLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
view.setLayoutParams(vLayoutParams);
viewGroup.addView(view);
editText = new GameEditText(this);
RelativeLayout.LayoutParams etLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
etLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
editText.setGravity(Gravity.BOTTOM);
editText.setLayoutParams(etLayoutParams);
viewGroup.addView(editText);
setContentView(viewGroup);
Here is my AndroidManifest.xml (the part the matters):
<activity
android:name="app.ember.MainActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="sensorLandscape"
android:windowSoftInputMode="adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Extra Information:
- GameView = is a GLSurfaceView
- GameEditText = is a EditText
- If I comment out the first line (getWindow().addFlags...) Then the game view pans upward and the view isn't visible, unless I start typing stuff.
- Leaving that first line in makes the game not pan, but doesn't move the editText field upward and the keyboard covers the editText field
Any suggestions?
Here are some fancy screenshots:
Game No Keyboard:
Game With Keyboard and WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
set (what it looks like in the monitor to show layer hierarchy):
Game With Keyboard and those flags NOT set.
Here is the desired output: