TabBar使用Custom EditText与Soft键盘一起向上移动

时间:2014-04-23 15:42:48

标签: android android-edittext tabbar

我使用自定义EditText在软键盘中使用发送选项保存多行文本。它工作正常,但我的标签栏与键盘一起移动到顶部。我在清单文件中使用了以下内容。

    android:windowSoftInputMode="adjustPan"
    android:windowSoftInputMode="adjustResize"

这些适用于普通的EditText。但如果我使用CustomEditText,则失败。

这是我的xml:

 <com.sample.helpers.CustomEditText 
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:hint="Description"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:textSize="16dp"
        android:id="@+id/et_description"

        />

我的自定义EditText类:

public class CustomEditText extends EditText {



public CustomEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

public CustomEditText(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    InputConnection connection = super.onCreateInputConnection(outAttrs);
    int imeActions = outAttrs.imeOptions&EditorInfo.IME_MASK_ACTION;
    if ((imeActions&EditorInfo.IME_ACTION_NEXT) != 0) {
        // clear the existing action
        outAttrs.imeOptions ^= imeActions;
        // set the DONE action
        outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
    }
    if ((outAttrs.imeOptions&EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
    }
    return connection;
}

}

截图:

enter image description here

所以,请指导我如何处理。

1 个答案:

答案 0 :(得分:1)

在Java代码中尝试此操作

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
相关问题