Edittext错误消息显示不正确

时间:2014-12-18 11:18:09

标签: android

在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 个答案:

答案 0 :(得分: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
    }   
});