Created
June 9, 2016 18:54
-
-
Save talhahasanzia/ae29fa5bbd699dfa548d141f6bccce96 to your computer and use it in GitHub Desktop.
Custom view example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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