2017-04-03 62 views
0

enter image description hereAndroid的錯誤Text_Input_Layout EDITTEXT

有誰知道我可以改變(如所附的圖像)錯誤浮動標籤的部分提到的位置?在圖片中,它在左邊,但我希望它位於edittext的右側(因爲我的母語)。我嘗試了重力和佈局重力,但沒有一個能解決問題。提前致謝 。

<android.support.design.widget.TextInputLayout 
android:id="@+id/numid" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:gravity="center" 
app:errorEnabled="true" 
app:errorTextAppearance="@style/myerror" 
android:layout_gravity="center" 
    app:hintTextAppearance="@style/TextAppearance.AppCompat.TextInputLayout" 
style="@style/EditScreenTextInputLayoutStyle"> 

<android.support.v7.widget.AppCompatEditText 
    android:id="@+id/tie" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:gravity="right" 
    android:textAlignment="gravity" 
    android:hint="@string/hint2" 
    android:textDirection="rtl" 
    /> 

<style name="TextAppearance.AppCompat.TextInputLayout" parent="@android:style/TextAppearance"> 
<item name="android:textColor">#ff0000</item> 
<item name="android:layout_gravity">right</item> 
<item name="android:textColorHint">#736f6e</item> 
<item name="android:gravity">right</item> 

<style name="EditScreenTextInputLayoutStyle" parent="Theme.AppCompat.Light"> 
<item name="colorControlNormal">#000</item> 
<item name="colorControlActivated">#000</item> 
<item name="colorControlHighlight">#ff0000</item> 
<item name="colorAccent">#ffff02</item> 
<item name="android:textColorHint">#0000ff</item> 
    </style> 

<style name="myerror" parent="TextAppearance.Design.Error"> 
    <item name="android:textColor">#ff0000</item> 
    <item name="android:background">#000000</item> 
    <item name="android:gravity">center</item> 

</style> 
+1

分享您的佈局文件。 – buzzingsilently

+0

'android:supportsRtl' ????? –

+0

@IntelliJ Amiya。 getWindow()。getDecorView()。setLayoutDirection(View.Layout_Di rection_RTL)。我如何將它用於edittext? –

回答

0

試試這個:

Drawable err_indiactor = ContextCompat.getDrawable(this,R.drawable.indicator_input_error); 
    yourEditText.setCompoundDrawablesWithIntrinsicBounds(null, null, err_indiactor, null); 

這是繪製對象indicator_input_error

enter image description here

+0

tnx。你知道我怎麼可以把浮動錯誤標籤文本從右側顯示到edittext的左側?@ rafsanahmad007 –

+0

看到這個:http://stackoverflow.com/questions/41099639/how-to-set-rtl-in -textinputlayout – rafsanahmad007

0

下面的代碼適用於ü

public class MainActivity extends Activity { 
    EditText use, pass; 

    Button button; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     use = (EditText) findViewById(R.id.edituse); 
     pass = (EditText) findViewById(R.id.editpas); 

     button = (Button) findViewById(R.id.click); 
     button.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       final String use1 = use.getText().toString(); 
       final String pass1 = pass.getText().toString(); 

       if (!use1.matches("") && !pass1.matches("")) { 
        Toast.makeText(getApplicationContext(), "Succes", 
          Toast.LENGTH_SHORT).show(); 

        use.setError(null); 
        pass.setError(null); 

       } else if (use1.matches("")) { 
        use.setError("This field can not be blank"); 
       } else if (pass1.matches("")) { 
        pass.setError("This field can not be blank"); 
       } 
      } 
     }); 

    } 
} 

和XML文件

<RelativeLayout 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="${relativePackage}.${activityClass}" > 

    <TextView 
     android:id="@+id/test" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Test" 
     android:textSize="25sp" 
     android:gravity="center" /> 

    <EditText 
     android:layout_below="@+id/test" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/edituse"/> 
    <EditText 
     android:layout_below="@+id/edituse" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/editpas" 
     /> 
<Button 
    android:id="@+id/click" 
    android:layout_below="@+id/editpas" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Click"/> 

</RelativeLayout> 

希望這有助於...和英語這works.For烏爾語言的一個權利左寫,那麼它可能是錯誤信息左對齊的問題.... ...不要擔心試試這個。

+0

謝謝,但我的問題完全是關於將浮動標籤放在右側,因爲我的語言是從右向左寫的。 –