EditText editText = findViewById(R.id.edit_text); editText.setGravity(Gravity.START);
EditText editText = findViewById(R.id.edit_text); editText.setGravity(Gravity.CENTER);This will set the text alignment to the center of the EditText widget. Package Library: android.view.Gravity The setGravity() method is a part of android.widget.EditText, which is present in the android.view package library. The Gravity class is also present in this package, and it provides constants for setting the gravity property of a widget.