EditText editText = new EditText(this); editText.setPadding(16,16,16,16);
In this example, we define an EditText view in XML and set padding of 8 dp on both the left and right sides. Package library: The android.widget.EditText setPadding() method is part of the Android SDK and is located in the android.widget package.