我想完成@格雷格恩尼斯 我希望這可以幫助你 我使用的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) {
}
});
告訴我們你的代碼 – Arlind
這個答案可能是有用的(或可能重複):http://stackoverflow.com/questions/35403731/hint-alignment-to-the-right-of-password-edittext –