Android Framework EditText Android 4. 4+: https://issuetracker.google.com/issues/37082815 https://code.google.com/p/android/issues/? id = 201471. 2016 .
:
( /RTL), textPassword (InputType.TYPE_TEXT_VARIATION_PASSWORD), .
, , InputType.TYPE_TEXT_VARIATION_PASSWORD, InputType.TYPE_TEXT_VARIATION_PASSWORD . , .
( LTR, , "abc123") , textDirection RTL.
:
AndroidManifest.xml:
<application
...
android:supportsRtl="true"
... >
</application>
XML- :
<EditText
android:id="@+id/password"
android:inputType="textPassword"
android:hint="סיסמא"
... />
Java- :
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login_fragment_layout, container, false);
final EditText password = (EditText) view.findViewById(R.id.password);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isRTL(getActivity())) {
password.setTextDirection(View.TEXT_DIRECTION_RTL);
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
password.addTextChangedListener(new TextWatcher() {
boolean inputTypeChanged;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isRTL(getActivity())) {
if (s.length() > 0) {
if (!inputTypeChanged) {
password.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
password.setSelection(s.length());
inputTypeChanged = true;
}
} else {
password.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
inputTypeChanged = false;
}
}
}
});
return view;
}
public static boolean isRTL(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return context.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL;
} else {
return false;
}
}
:
