I need to draw a rounded rectangle in the Android UI. Having the same rounded rectangle for TextView and EditText would also be helpful.
In monodroid, you can do like this for rounded rectangle, and then keeping this as a parent class, editbox and other layout features can be added.
class CustomeView : TextView
{
public CustomeView (Context context, IAttributeSet ) : base (context, attrs)
{
}
public CustomeView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
}
protected override void OnDraw(Android.Graphics.Canvas canvas)
{
base.OnDraw(canvas);
Paint p = new Paint();
p.Color = Color.White;
canvas.DrawColor(Color.DarkOrange);
Rect rect = new Rect(0,0,3,3);
RectF rectF = new RectF(rect);
canvas.DrawRoundRect( rectF, 1,1, p);
}
}
}
Right_click on the drawable and create new layout xml file in the name of for example button_background.xml. then copy and paste the following code. You can change it according your need.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="14dp" />
<solid android:color="@color/colorButton" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<size
android:width="120dp"
android:height="40dp" />
</shape>
Now you can use it.
<Button
android:background="@drawable/button_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>