package com.example.custom;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class Custom extends View {
final Paint mPaint = new Paint();
public Custom(Context context) {
super(context);
mPaint.setColor(Color.BLACK);
mPaint.setTextSize(30);
}
@Override
protected
void onDraw(Canvas canvas) {
super.onDraw(canvas);
setBackgroundColor(Color.CYAN);
canvas.drawText("Custom Text", 100, 100, mPaint);
invalidate();
}
}
package com.example.custom;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Custom(this));
}
}
No comments:
Post a Comment