Scratch Card in Android jetpack compose
CardScratching is an Android library that empowers app developers to integrate an interactive scratch card feature into their applications. With CardScratching, users can virtually ‘scratch’ a card on their device’s screen, revealing concealed content underneath. This content is often used to showcase coupon codes, discounts, or other rewards, enhancing user engagement and creating an enjoyable interaction. The library offers customization options for the scratch card’s appearance, making it easy to match the app’s design. By leveraging CardScratching, developers can seamlessly introduce gamified elements to their apps, resulting in increased user interaction and satisfaction.
- Interactive Scratching: The library provides a touch-sensitive interface that simulates the act of scratching a surface to unveil hidden information.
- Customizable Design: Developers can customize the appearance of the scratch card, including its size, shape, colors, and text.
- Revealing Content: Underneath the scratched area, the library reveals content such as a coupon code, discount information, or any other rewards.
- Integration: The library can be integrated easily into existing Android apps, providing developers with a pre-built solution for adding scratch card functionality.
Now it’s time to implement the card scratching to your project:
Step 1: Add the Dependency
Add the ScratchCardCompose dependency to your app’s build.gradle file:
dependencies {
implementation 'com.github.JaberAhamed:CardScratch:1.0'
}
Add the maven dependency to your root build.gradle
file:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2: Use ScratchCard in Your Composable
Now just add the below code for the image card scratch :
ImageScratch(
overlayImage = ImageBitmap.imageResource(R.drawable.overlay),
baseImage =
ImageBitmap.imageResource(R.drawable.base),
)
Then you will show the Imagescratch view
If you want to implement the only card scratch then you have to add the below code :
CardScratch(
cardBackgroundColor = Color.Red.copy(0.6f),
title = "Scratch & Win",
titleTextColor = Color.White,
scratchText = "Coupon code is: 457896",
)
Now you will show the CardScrach view
Awesome!🎉 you have implemented Scratchcard to your project. GitHub
Happy scratching and coding! 🚀📱