在使用EditText控件時,經常需要指定android:inputType屬性,比如用戶名輸入框,密碼輸入框等。
而不同的android:inputType屬性有時候會有使用不同的字體,比如textPassword, 這會造成密碼框同用戶名框的hint字體不一致,影響整體的美觀性。
這個時候可以通過Java Code對EditText控件進行調整,使得用戶名輸入框同密碼輸入框的hint具有相同的字體。
Ex.
EditText etPassword = findViewById(R.id.etPassword);
etPassword.setTypeface(Typeface.DEFAULT);
etPassword.setTransformationMethod(new PasswordTransformationMethod());
通過簡單的兩行代碼就能夠將密碼輸入框hint的字體設置跟用戶名輸入框的一致。