Adding Floating Icon in Android Studio Kotlin

 Adding Floating Icon in Android Studio Kotlin

First of all, add the dependencies as shown in the given code below.



plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdk 30

defaultConfig {
applicationId "com.shyptsolution.myresume"
minSdk 23
targetSdk 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.6.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'com.squareup.picasso:picasso:2.71828'
}

Then you need to add the floating icons in the XML as shown below.
First add the <com.google.android.material.floatingactionbutton.FloatingActionButton
then all the things such as icon, id, its position and everything else you want.


<?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="@drawable/bgcol"
tools:context=".MainActivity">

<!--<com.google.android.material.bottomappbar.BottomAppBar-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:id="@+id/bottamappbar"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->

<!-- >-->


<!--</com.google.android.material.bottomappbar.BottomAppBar>-->

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome Aleem Ahmad"
android:textColor="@color/white"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/floatinghome"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatinghome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:src="@drawable/home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<!-- app:layout_anchor="@id/bottamappbar"-->
<!-- app:layout_constraintBottom_toBottomOf="@+id/bottamappbar"-->
<!-- app:layout_constraintEnd_toEndOf="@+id/bottamappbar"-->
<!-- app:layout_constraintStart_toStartOf="@+id/bottamappbar" -->
/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:src="@drawable/contact_me"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginLeft="20dp"
app:layout_constraintStart_toStartOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/resume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:src="@drawable/resume"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginRight="20dp" />
</androidx.constraintlayout.widget.ConstraintLayout>


And now you are done. Enjoy it now.


Post a Comment

0 Comments