Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Created June 9, 2016 18:54
Show Gist options
  • Save talhahasanzia/ae29fa5bbd699dfa548d141f6bccce96 to your computer and use it in GitHub Desktop.
Save talhahasanzia/ae29fa5bbd699dfa548d141f6bccce96 to your computer and use it in GitHub Desktop.
Custom view example
public class RgbView extends View {
Paint p=new Paint();
public RgbView(Context context) {
super(context);
init(null, 0);
}
public RgbView(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public RgbView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs, defStyle);
}
private void init(AttributeSet attrs, int defStyle) {
p.setColor(Color.RED);
}
public void setColor(int Red, int Green, int Blue)
{
p.setARGB(255, Red, Green, Blue);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(0,0, getHeight(),getWidth(),p);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment