xpol
xpol

Reputation: 172

Android EditText pushed down by action bar

I add a EditText in my Android cocos2d-x based game.

The "Select Cut Copy Paste" action bar pushes my EditBox down.

compare

And what I want is like this:

enter image description here

Here is the code I setup my edit box position:

public void setEditBoxViewRect(int left, int top, int maxWidth, int maxHeight) {
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                                                                        FrameLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.leftMargin = left;
    layoutParams.topMargin = top;
    layoutParams.width = maxWidth;
    layoutParams.height = maxHeight;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    this.setLayoutParams(layoutParams);
}

I think the problem is that I customised my EditText layout. And when the action bar shows, I did not respond related event to adjust my EditText position.

Can I listen on the event the menu bar shows and get the correct height to adjust my EditText?

I tried this code, but it just disable the action bar:

edittext.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {

        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });

Upvotes: 0

Views: 638

Answers (2)

zneil
zneil

Reputation: 1

add styles.xml,like this:

<resources xmlns:tools="http://schemas.android.com/tools">


    <style name="Activity.Theme.Full" parent="@android:style/Animation.Activity">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>

</resources>

change manifest like this:

<activity android:name=".AppActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="sensorLandscape"

                  android:theme="@style/Activity.Theme.Full" 

notice that the build target is 22 (i only test it) or more

Upvotes: 0

xpol
xpol

Reputation: 172

The key answer is android:windowActionModeOverlay

in res/style.xml define a new theme extends your original theme:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Black.NoTitleBar.ActionModeOverlay" parent="android:Theme.Black.NoTitleBar">
    <item name="android:windowActionModeOverlay">true</item>
  </style>
</resources>

or just add a line <item name="android:windowActionModeOverlay">true</item> in your theme if you have already defined one.

Make your Activity use the theme defined above in AndroidManifest.xml:

<manifest ...>


<application ...>

    <activity
        android:name="you.AppActivity"
        android:theme="@style/ActionModeOverlay" >

Upvotes: 1

Related Questions