2017-04-17 40 views
-3

有没有人有一个想法如何在操作栏后面显示错误消息?Android编辑文本错误重叠操作栏

enter image description here

请检查这是设计的我的xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_second" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    <EditText 
      android:id="@+id/editTextlastname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="lastname" 
      android:layout_marginTop="15dp" 
      android:paddingBottom="1000dp" 
      android:inputType="text"/> 

    </RelativeLayout> 
</ScrollView> 

+1

发表您的XML代码 –

+1

如果您使用相对布局,然后使用标签>> 机器人:layout_below =“...” –

+0

尝试添加android:paddingTop =“?android:attr/actionBarSize”到父布局 – Raghavendra

回答

0

我想你同时做所有的编辑文本的确认(在使用if块||)逐个进行验证(使用& &而不是||),它会自动将您的姓氏代码聚焦在操作栏下面并显示错误消息。

0

如果您使用RelativeLayout作为您的主父布局,请将其更改为LinearLayout并将方向设置为Vertical

0

我得到这个问题的解决方案,请尝试这种

scrollView.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      if (yourEditText.getError() != null) { 
       yourEditText.setError(null); 
       return true; 
      } 
      return false; 
     } 
    });