2017-12-26 34 views
2

ツールバーの中にEditTextビューを使用しています。「チェック」アイコンをクリックすると、すべてのフィールドが空であるかどうかがチェックされます。 ifが空の場合、setError()メソッドが呼び出されます。しかし、ポップアップメッセージは奇妙に見えます(下の図)。 enter image description hereEditText.setError()のポップアップメッセージレイアウトが奇妙に見える

私はソフト入力を隠すので、このように見えます。 enter image description here

別の問題はEditTextビューがルートレイアウトになっていることであり、そしてsetError()が呼び出されたときに、ビューが自動的に(Appbarlayoutが隠されている)までスクロール。レイアウトを正しくビューの下に置く方法enter image description here

これはレイアウトデザインの問題ですか?

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

テストケースの削除 ''はtryよりも優先されます –

答えて

0
  • uは 特定の期間のために適切なメッセージを表示することができますようあなたはずっと良く見えるその検証として、スナックバーを使用して カスタマイズを持つことができます...例:textChangedListenerにまたはボタンをクリック - >

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

    あなたもtextChangedListener ... およびVIのために使用することができますewは自動的にseterrorのようにスクロールしません

関連する問題