android - Edittext 错误信息显示不正确

标签 android

在 htc one v android 4.0.3 上测试

Activity :

    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

预期行为:错误消息显示在正确的位置。任何人都知道如何解决它? 谢谢!

最佳答案

试试这个: 试试这个:

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

关于android - Edittext 错误信息显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27545323/

相关文章:

java - fragment 创建和检索并发

android - 唯一标识每个设备,访问sencha web应用程序

android - 触发 Android Studio 以显示方法签名?

java - 如何在android上使用AccessibilityService获取屏幕上的View对象?

Android VideoView 错误 1,0

android - 添加新表 onUpgrade android

android - Android Fragment是Linux进程吗?

适用于多种语言的android tts

android - 安装 Delphi 10.4 Android SDK 时出现问题

android - 如何将简单的图像制作成像GIF这样的动画图像?