2015-04-12 54 views
2

我有一個EditText,inputType設置爲textPassword。 我希望輸入將是從左到右的數字,但我想將提示與EditText的右側對齊。 當我試着gravity=right它看起來沒問題,但是當用戶點擊EditText時,光標位於最左邊的位置,並且他不能刪除文本。如果他想刪除文本,他需要將光標放在最正確的位置。在EditText中對齊提示文本inputType = textPassword,對於從右至左(RTL)語言

任何想法如何我可以享受這兩個世界?

使用EditText與inputType=textPassword,提示對齊到右側,並從左到右插入數字?

注:這似乎是在Android框架中的錯誤,使用Android的:的inputType = 「textPassword」:https://code.google.com/p/android/issues/detail?id=201471

<EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="textPassword" 
     android:ems="10" 
     android:id="@+id/txt_password" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:hint="סיסמא" 
     android:gravity="right" /> 

clicking the edittext puts the cursor at the left position and I can't delete the text now

empty edittext 感謝

+0

告訴我們你的代碼 – Arlind

+0

這個答案可能是有用的(或可能重複):http://stackoverflow.com/questions/35403731/hint-alignment-to-the-right-of-password-edittext –

回答

0

的EditText上是用於將提示文本與用戶輸入的文本對齊。通過將圖像和文本放置在EditText的右側,我已經完成了這一工作,只是定義與其右側對齊的另一個視圖。

你需要有父視圖是一個RelativeLayout的做到這一點,但它工作得很好:

<EditText android:id="@+id/test" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<TextView android:id="@+id/hint" 
    android:text="Something" 
    android:layout_alignRight="@id/test" 
    android:layout_alignBottom="@id/test" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
+0

對不起,但我不理解你的解決方案。另一個textview將如何幫助我在這裏? –

0

我想完成@格雷格恩尼斯 我希望這可以幫助你 我使用的EditText爲密碼和一個TextView它的提示象下面這樣:

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    <EditText 
     android:id="@+id/password" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:background="@color/white" 
     android:inputType="textPassword" 
     android:padding="10dp" 
     android:singleLine="true" 
     android:textColor="@color/input_login" 
     android:textColorHint="@color/input_login_hint" 
     /> 
     <TextView android:id="@+id/hint" 
     android:hint="@string/hint_password" 
     android:background="@color/white" 
     android:textColorHint="@color/input_login_hint" 
     android:padding="10dp" 
     android:singleLine="true" 
     android:layout_alignRight="@id/password" 
     android:layout_alignTop="@id/password" 
     android:textSize="17dp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/password" 
     /> 
    </RelativeLayout> 

,我寫在下面onCreate方法來隱藏TextView的提示時輸入密碼代碼:

EditText edtPassword; 
    TextView txtHint; 
    edtPassword = (EditText) findViewById(R.id.password); 
    txtHint = (TextView) findViewById(R.id.hint); 

    edtPassword.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 
      String enterPass = edtPassword.getText().toString(); 

      if(start == 0){ 
       txtHint.setHint(R.string.hint_password); 


      }else { 
       txtHint.setHint(""); 
      } 

     } 

     @Override 
     public void afterTextChanged(Editable s) { 

     } 
    }); 
相關問題