Skip to main content

Posts

Showing posts with the label Paint

android kotlin - Paint gradient path

MainActivity.kt package com.cfsuman.kotlintutorials import android.app.Activity import android.graphics.* import android.os.Bundle import android.widget.* class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // get the widgets reference from XML layout val imageView = findViewById<ImageView>(R.id.imageView) // show drawing on image view imageView.setImageBitmap( drawGradientPath() ) } } // function to draw gradient path on canvas fun drawGradientPath():Bitmap?{ val bitmap = Bitmap.createBitmap( 1500, 850, Bitmap.Config.ARGB_8888 ) // canvas for drawing val canvas = Canvas(bitmap).apply { drawColor(Color.parseColor("#FEFEFA")) } // initialize a rectF instance val margin = 50F val rectF = RectF( ...

android kotlin - Paint linear gradient

MainActivity.kt package com.cfsuman.kotlintutorials import android.app.Activity import android.graphics.* import android.os.Bundle import android.widget.* class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // get the widgets reference from XML layout val imageView = findViewById<ImageView>(R.id.imageView) // show drawing on image view imageView.setImageBitmap( drawLinearGradient() ) } } // function to draw linear gradient on canvas fun drawLinearGradient():Bitmap?{ val bitmap = Bitmap.createBitmap( 1500, 850, Bitmap.Config.ARGB_8888 ) // canvas for drawing val canvas = Canvas(bitmap).apply { drawColor(Color.parseColor("#FEFEFA")) } // initialize a rectF instance val margin = 50F val rectF = RectF( ...

Android Kotlin: Paint gradient circle

Introduction This article explores how to create a radial gradient circle in an Android application using Kotlin. The implementation involves drawing on a Canvas object, using a combination of Kotlin and Android's powerful graphics APIs. The aim is to produce a visually appealing gradient circle with smooth transitions between colors, providing a dynamic and engaging effect for Android users. In this example, we walk through the steps involved in setting up the MainActivity , drawing the gradient circle, and displaying it in an ImageView widget. This tutorial is geared toward Android developers familiar with Kotlin, who are looking to enhance their app’s graphical capabilities by implementing custom drawing logic. Breakdown of the Code : Activity Setup in MainActivity The MainActivity class extends Android's Activity and serves as the main entry point for our app. In the onCreate() method, the activity's layout is set using the setContentView() method, which inflates ...

How to convert Hex color to int color in Android

activity_main.xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#DCDCDC" android:padding="24dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="200dp" android:layout_height="75dp" android:text="Change My Color" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTop...