简体   繁体   English

将EditText放在软键盘上方

[英]Put EditText above the soft keyboard

I am using 2 FrameLayout both have EditText in it, if I click the editText which is at the bottom of the layout can be seen above the softKeyboard but if I click the editBox which frameLayout is above the other FrameLayout place does not change and placed behind the keyboard and the frameLayout which is at the bottom again change its place and it shown above the soft keyboard. 我正在使用2 FrameLayout都具有EditText,如果我单击在布局底部底部的editText可以在softKeyboard上方看到,但是如果我单击editBox且frameLayout在另一个FrameLayout上方则不会更改并放置在后面键盘和位于底部的frameLayout再次更改其位置,并显示在软键盘上方。

I tried, 我试过了,

mMessageBox.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        Commons.logCatchya("onFocusListener changed !");
        if (hasFocus) {
            Commons.logCatchya("onFocusListener hasFocus !");   
        }
        else {
            Commons.logCatchya("onFocusListener do not hav focus !");
        }
    }
});

mMessageBox.setOnKeyListener(new View.OnKeyListener() {

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        Commons.logCatchya("setOnKeyListener :" + event.getAction() + " keyCode :" + keyCode);
        return false;
    }
});


mProfileStatusBox.setOnFocusChangeListener(new View.OnFocusChangeListener() {

    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        Commons.logCatchya("onFocusListener mProfileStatusBox changed !");
        if (hasFocus) {
            Commons.logCatchya("onFocusListener mProfileStatusBox hasFocus !"); 
        }
        else {
            Commons.logCatchya("onFocusListener mProfileStatusBox do not hav focus !");
        }

    }
});

but if I click hide soft keyboard button on screen the curser is still on the editbox that I used. 但是,如果我单击屏幕上的“隐藏软键盘”按钮,则光标仍在我使用的编辑框中。 Is this problem because of the FrameLayout ? 这是由于FrameLayout引起的吗? İf not what should I do to solve this issue. 如果不解决该问题,该怎么办。

Set this for your activity tag in your Activity 在“活动”中为您的活动标签设置此项

android:configChanges="keyboardHidden|orientation"

if it doesn't worked for you try to set your parent layout in ScrollView 如果对您不起作用,请尝试在ScrollView中设置父布局

I'm sure you're using LinearLayout setting its width and height to full_parent . 我确定您正在使用LinearLayout将其widthheight设置为full_parent
Don't do that, use RelativeLayout instead setting the height to: 请勿这样做,而是使用RelativeLayoutheight设置为:

android:layout_height="wrap_content"

I solved the problem by using RelativeLayout and using 我通过使用RelativeLayout和使用解决了问题

android:gravity="bottom"

in the layout file. 在布局文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM