2017-04-03 66 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

谢谢,但我的问题完全是关于将浮动标签放在右侧,因为我的语言是从右向左写的。 –