2015-11-16 22 views
0

我在我的基於Android cocos2d-x的遊戲中添加了一個EditText。Android EditText被操作欄按下了

「選擇剪切複製粘貼」操作欄將我的編輯框向下推。

compare

而且我想是這樣的:

enter image description here

下面是代碼設置我的編輯框位置:

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); 
} 

我認爲問題是,我自定義了我的EditText佈局。當操作欄顯示時,我沒有響應相關事件來調整我的EditText位置。

我可以聽菜單欄顯示的事件並獲得正確的高度來調整我的EditText嗎?

我嘗試這樣的代碼,但它只是禁用操作欄:

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; 
     } 
    }); 

回答

1

的關鍵答案是android:windowActionModeOverlay

res/style.xml定義一個新的主題擴展您的原始主題:

<?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> 

,或者只需在主題中添加一行<item name="android:windowActionModeOverlay">true</item>即可。

讓您的活動使用AndroidManifest.xml上面定義的主題:

<manifest ...> 


<application ...> 

    <activity 
     android:name="you.AppActivity" 
     android:theme="@style/ActionModeOverlay" > 
0
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