Button myButton = new Button(this); myButton.setText("Click Me"); myLayout.addView(myButton);
public class MyCustomView extends View { public MyCustomView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //Draw a circle Paint p = new Paint(); p.setColor(Color.RED); canvas.drawCircle(getWidth() / 2, getHeight() / 2, 100, p); } }In this example, we create a custom View subclass and override the onDraw() method to draw a circle shape using the Canvas API. Package Library: The View class is part of the Android SDK platform libraries, which is included in the android.view package.