Reputation: 20910
I have test on MarshMallow
device. When I write xml for EditText
and set PaddingBottom
to Retype EditText
. but it is not Working. But When I set PaddingLeft
to New PassWord
EditText
is working fine.
xml Code :
<EditText
android:id="@+id/change_password_old_password_edittext"
android:layout_below="@+id/change_password_mobileNumber_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Old Password"
android:layout_marginTop="20.0dip"
android:textColorHint="#40000000"
android:textSize="@dimen/textsize16"/>
<EditText
android:id="@+id/change_password_new_password_edittext"
android:layout_below="@+id/change_password_old_password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="New Password"
android:layout_marginTop="20.0dip"
android:textColorHint="#40000000"
android:paddingLeft="10dip"
android:textSize="@dimen/textsize16"/>
<EditText
android:id="@+id/change_password_retype_password_edittext"
android:layout_below="@+id/change_password_new_password_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Retype Password"
android:layout_marginTop="20.0dip"
android:paddingBottom="10dip"
android:textColorHint="#40000000"
android:textSize="@dimen/textsize16"/>
ScreenShot :
Then I decide to set PaddingBottom
programatically. But It is giving weird Output.
java code :
inside OnCreate
method
EditText change_password_retype_password_edittext = (EditText)findViewById(R.id.change_password_retype_password_edittext);
change_password_retype_password_edittext.setPadding(0,0,0,10);
Output :
Note : I have tested on
Marshmallow
,LolliPop
and alsoJellybean
. But in all device is not Working.
Upvotes: 1
Views: 3431
Reputation: 1789
Try to use this:
android:drawablePadding="8dp"
This padding will to put away the drawable from text cursor Look the example.
Upvotes: 0
Reputation: 4510
Your are not specifying the unit of padding you have set so it is taking pixel
by default which is smaller then dp
so the results are not as per your expectations.
Convert the pixels to dp you will get the solution :
int paddingPixel = 10;
float density = getResources().getDisplayMetrics().density;
int paddingDp = (int)(paddingPixel * density);
change_password_retype_password_edittext.setPadding(0,0,0,paddingDp);
For more info visit : Add padding on view programmatically
Upvotes: 6