Learn to make a Paint Application by using this PaintView library for Android
Hello everyone!
if you want to make an application or required Drawing in your project then this the best place for you.
today we will learn how to implement PaintView in your app.
I found an amazing library for it which is PaintView. We should say thanks to GURUDATT DAHARE for making this library for us.
So this is the Official link for Github Libary Repository: Click here
How to implement :
Step 1: Add it to your root build.gradle at the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2: Add dependencies
dependencies {
implementation 'com.github.GURUDATTDAHARE:PaintView:<latest version>'
}
Step 3: Add PaintView tag in your .xml file where you want drawing
<com.gurudattdahare.paint.PaintView
android:id="@+id/paintview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.gurudattdahare.paint.PaintView>
Step 4 (optional): implement OnEventListener
if you want to do some extra things when buttons are clicked then you need to implement OnEventListener.
mPaintView.setEvantListenar(new OnEventsListener() {
@Override
public void OnRedClicked() {
Toast.makeText(getApplicationContext(),"red is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnBlueClicked() {
Toast.makeText(getApplicationContext(),"blue is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnYellowClicked() {
Toast.makeText(getApplicationContext(),"yellow is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnGreenClicked() {
Toast.makeText(getApplicationContext(),"green is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnBlackClicked() {
Toast.makeText(getApplicationContext(),"black is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnBrownClicked() {
Toast.makeText(getApplicationContext(),"brown is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnEraserClicked() {
Toast.makeText(getApplicationContext(),"eraser is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnClearClicked() {
Toast.makeText(getApplicationContext(),"clear screen is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnBrushSizeClicked() {
Toast.makeText(getApplicationContext(),"brush size button is clicked.",Toast.LENGTH_SHORT).show();
}
@Override
public void OnUndoClicked() {
Toast.makeText(getApplicationContext(),"undo button is clicked.",Toast.LENGTH_SHORT).show();
}
This is the final output :
I hope you like this implementation. please share this with your friends and don’t forget to follow me for useful content.
Hemant Patel
Android App Developer | UI Designer | Competitive Programmer
Github | Linkedin | Medium | StackOverflow | GeeksforGeeks