Android Question edittext box radius

klaus

Expert
Licensed User
Longtime User
Yes, you can.
You can set a simple ColorDrawable:
B4X:
Dim cdw1 As ColorDrawable
cdw1.Initialize(Colors.White, 5dip)
edtTest1.Background = cdw1
Or set a simple GradientDrawable:
B4X:
Dim gdw2 As GradientDrawable
Dim Cols(2) As Int
Cols(0) = Colors.Red
Cols(1) = Colors.Blue
gdw2.Initialize("TOP_BOTTOM", Cols)
gdw2.CornerRadius = 5dip
edtTest2.Background = gdw2
Or better, set a StateListDrawable, which sets three backgrounds for Focused, Disabled and Enabled :
B4X:
Dim stw As StateListDrawable
Dim cdw3, cdw4, cdw5 As ColorDrawable
cdw3.Initialize(Colors.White, 5dip)
cdw4.Initialize(Colors.Gray, 5dip)
cdw5.Initialize(Colors.RGB(255, 204, 204), 5dip)
stw.Initialize
stw.AddState(stw.State_Focused, cdw5)
stw.AddState(stw.State_Disabled, cdw4)
stw.AddState(stw.State_Enabled, cdw3)
edtTest3.Background = stw
For the StateListDrawable you could use any type of Drawables even mix them.

You could also consider NinePatchDrawables (User's Guide chapter 10.1.5 NinePatchDrawable).

Be aware that ColorDrawable and GradientDrawable fill the whole surface of the EditText.
The default background surface is a bit smaller than the EditText dimensions.
 
Upvote 0
Top