在ActionBar上滚动的Android setError()消息

时间:2021-08-08 21:45:10

My issue is that the error message in my EditTexts are scrolling on top of the action bar. Is this an android bug, or am I doing something wrong?

我的问题是,EditTexts中的错误消息正在操作栏的顶部滚动。这是一个android bug,还是我做错了什么?

Also this bug happens even when the keyboard is down, it just happens to be up in the screenshots.

而且这个错误即使在键盘关闭的时候也会发生,它只是出现在屏幕截图中。

Here is what I am talking about: http://imgur.com/fG8bd3E,uFzhOXa#1 <- there are two images

这里是我正在谈论的:http://imgur.com/fG8bd3E,uFzhOXa#1 <-有两个图片

Here is my layout, I add the EditTexts in my code to the kiosk_form_table LinearLayout

这是我的布局,我将代码中的edittext添加到kiosk_form_table线性布局中

<ScrollView
    style="@style/DefaultBackground"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.6"
    android:fadeScrollbars="false"
    android:padding="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingRight="20dp" >

        <LinearLayout
            android:id="@+id/kiosk_form_table"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />

        <Button
            android:id="@+id/kiosk_submit_large"
            style="@style/LoginButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:onClick="submit"
            android:text="@string/submit" />
    </LinearLayout>
</ScrollView>

How I add the EditTexts

如何添加EditTexts

kiosk_form.addView(getKioskRow(R.layout.kiosk_text_row, "First Name", true, null));

private View getKioskRow(int layout, String header, boolean required, String buttonName)
{
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(layout, null);
    view.setTag(required);
    addHeader((TextView) inflater.inflate(R.layout.field_header, null), header);
    if (required)
        ((TextView) view.findViewById(R.id.kiosk_input)).setHint("Required");
    if (buttonName != null)
        ((Button) view.findViewById(R.id.kiosk_input_button)).setText(buttonName);
    return view;
}

private void addHeader(TextView view, String header)
{
    view.setTag(false);
    view.setText(header);
    kiosk_form.addView(view);
}

How I set the error

如何设置错误

(TextView) view).setError(getString(R.string.error_field_required));

3 个解决方案

#1


0  

Where do you want to see the error message? If you want it on EditText, set it on editText.

您希望在哪里看到错误消息?如果你想要它在EditText,设置它在EditText。

((EditText) findViewByID(R.id.my_edit_text)).setError ...... // and so on

Edit: original answer didn't help.

编辑:原始的答案没有帮助。

Here's one possible solution: you can hide the error message when the user is scrolling the view. When the scroll has finished you can re-set the error message and it should appear in the right spot! Here's how you can detect when a scroll finished: Android: How to detect when a scroll has ended

这里有一个可能的解决方案:当用户滚动视图时,您可以隐藏错误消息。当滚动完成后,您可以重新设置错误消息,它应该出现在正确的位置!以下是如何检测滚动何时结束的方法:Android:如何检测滚动何时结束

#2


2  

It is Android OS bug. You can track its progress here

这是Android操作系统的漏洞。你可以在这里追踪它的进程

#3


0  

I resolve similiar problem by setting flag

我通过设置标志来解决类似问题。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

#1


0  

Where do you want to see the error message? If you want it on EditText, set it on editText.

您希望在哪里看到错误消息?如果你想要它在EditText,设置它在EditText。

((EditText) findViewByID(R.id.my_edit_text)).setError ...... // and so on

Edit: original answer didn't help.

编辑:原始的答案没有帮助。

Here's one possible solution: you can hide the error message when the user is scrolling the view. When the scroll has finished you can re-set the error message and it should appear in the right spot! Here's how you can detect when a scroll finished: Android: How to detect when a scroll has ended

这里有一个可能的解决方案:当用户滚动视图时,您可以隐藏错误消息。当滚动完成后,您可以重新设置错误消息,它应该出现在正确的位置!以下是如何检测滚动何时结束的方法:Android:如何检测滚动何时结束

#2


2  

It is Android OS bug. You can track its progress here

这是Android操作系统的漏洞。你可以在这里追踪它的进程

#3


0  

I resolve similiar problem by setting flag

我通过设置标志来解决类似问题。

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);