2017-12-26 15 views
2

Ich benutze eine EditText Ansicht in meiner Symbolleiste, und wenn das "Häkchen" -Symbol angeklickt wird, wird die App überprüfen, ob alle Felder leer sind oder nicht. Wenn leer ist, wird die Methode setError() aufgerufen. Aber die Popup-Nachricht sieht seltsam aus (in der folgenden Abbildung). enter image description hereEditText.setError() 's Popup-Nachrichtenlayout sieht seltsam aus

Und ich verstecke weiche Eingabe, es sieht so aus. enter image description here

Ein weiteres Problem ist, dass eine EditText Ansicht im Wurzel Layout ist, und, wenn setError() genannt wird, gescrollt die Ansicht automatisch up (Appbarlayout ist verdeckt). Wie lässt sich das Layout korrekt unter der Ansicht platzieren? enter image description here

Ist das das Layout-Design-Problem?

layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     > 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/tool_bar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:minHeight="?attr/actionBarSize" 
      android:theme="@style/ActionbarStyle" 
      app:layout_scrollFlags="scroll|enterAlways|snap"> 

      <EditText 
       android:id="@+id/et_ItemName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/item_name" 
       android:inputType="text|textAutoCorrect" 
       android:maxLength="20" 
       android:textStyle="bold"> 

       <requestFocus /> 
      </EditText> 
     </android.support.v7.widget.Toolbar> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/layout_padding" 
     android:paddingLeft="@dimen/layout_padding" 
     android:paddingRight="@dimen/layout_padding" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        app:srcCompat="@drawable/ic_money_black_24dp" /> 

       <EditText 
        android:id="@+id/et_Dollar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        android:gravity="end|right" 
        android:inputType="numberDecimal" 
        android:textStyle="bold" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_vertical" 
        app:srcCompat="@drawable/ic_sort_black_24dp" /> 

       <Button 
        android:id="@+id/btn_SelectCategory" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="?attr/selectableItemBackground" 
        android:clickable="true" 
        android:gravity="end|right|center_vertical" 
        android:hint="@string/select_category" /> 
      </LinearLayout> 

      <EditText 
       android:id="@+id/et_Note" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="@drawable/background_border" 
       android:gravity="top|left" 
       android:hint="@string/note" 
       android:inputType="textMultiLine" 
       android:minLines="1" 
       android:padding="@dimen/TextPAdding" /> 

      <include 
       android:id="@+id/view_image_container" 
       layout="@layout/layout_add_photo" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginTop="@dimen/widget_padding" /> 

     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 

</android.support.design.widget.CoordinatorLayout> 
+0

für testfall entfernen '' als versuchen –

Antwort

0
  • Sie können als Validation Snackbar verwenden, die viel besser aussieht und haben Anpassung als u richtige Nachricht für bestimmte Zeit Zeit zeigen kann ... Beispiel: auf textChangedListener oder auf Knopf klicken ->

    submitBT = (Button) findViewById(R.id.submitBT); 
    
         submitBT.setOnClickListener(new View.OnClickListener() { 
          @Override 
          public void onClick(View v) { 
           if (loginET.getText().toString().isEmpty() || loginET.length() == 0 || loginET.length() > 50) { 
          Snackbar.make(view, "Please Enter Username/Email", Snackbar.LENGTH_SHORT).show(); 
          return; 
         } 
         if (passwordET.getText().toString().isEmpty() || passwordET.length() == 0 || passwordET.length() > 50) { 
          Snackbar.make(view, "Password", Snackbar.LENGTH_SHORT).show(); 
         } 
          } 
         }); 
    

    Sie können auch für textChangedListener verwenden ... und vi ew wird nicht automatisch scrollen wie seterror

Verwandte Themen