How to draw rounded rectangle in Android UI?

前端 未结 8 1005
北海茫月
北海茫月 2020-11-27 11:46

I need to draw a rounded rectangle in the Android UI. Having the same rounded rectangle for TextView and EditText would also be helpful.

8条回答
  •  醉话见心
    2020-11-27 12:35

    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);
    
    
    
           }  
        }
    }
    

提交回复
热议问题