EditText错误信息显示不正确。

3

本文涉及的测试机型为htc one v,操作系统版本为Android 4.0.3。

活动:

    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.widget.EditText;


    public class MainActivity extends ActionBarActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            EditText editText = (EditText) findViewById(R.id.editText);
            editText.setError("Error msg");
        }

    }

Xml:

  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_gravity="bottom"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
            </LinearLayout>
    </FrameLayout>

步骤: enter image description here enter image description here enter image description here 期望行为:错误信息应显示在正确的位置。有人知道如何修复吗? 谢谢!

1
这是你的错误显示代码。XML文件中没有它,请发布你的Java代码。 - Md Abdul Gafur
在清单文件中的活动中尝试添加 android:windowSoftInputMode="adjustResize" - Shayan Pourvatan
adjustResize可以使用,但它不适合我,因为此选项会调整布局大小。 - Sinigami
<EditText ... android:layout_height="wrap_content">尝试使用match_parent(按钮可能会变得不可见)。如果问题消失,请改用RelativeLayout而不是线性布局。 - 18446744073709551615
1个回答

0
试试这个: 试试这个:
InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);

/*
Instantiate and pass a callback
*/
SoftKeyboard softKeyboard;
softKeyboard = new SoftKeyboard(mainLayout, im);
softKeyboard.setSoftKeyboardCallback(new SoftKeyboard.SoftKeyboardChanged() {

@Override
    public void onSoftKeyboardHide() 
{
        // Here request your errorMessage
    }
@Override
    public void onSoftKeyboardShow() 
{
        // Here request your errorMessage
    }   
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接