Step 1: Add Jitpack repository in your root build.gradle file (not your module build.gradle file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2: Add dependency to your module's build.gradle file:
dependencies {
compile 'com.github.aniketbhoite:MutativeFab:1.0.8'
}
Add floating text button to your layout file like this:
<com.aniket.mutativefloatingactionbutton.MutativeFab
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabIcon="@drawable/ic_location"
app:fabText="relocate"
android:layout_alignParentBottom="true"
app:fabBackgroundColor="@android:color/white"
app:fabTextColor="@color/colorPrimary"
android:layout_alignParentEnd="true"/>
In Java or Kotlin
mFab.setFabText("start chat");
mFab.setFabTextColor(ContextCompat.getColor(context, R.color.textColor));
mFab.setFabIcon(R.drawable.ic_chat);
mFab.setFabBackgroundColor(ContextCompat.getColor(context, android.R.color.holo_blue_dark));
mFab.setFabTextVisibility(View.VISIBLE);//or View.GONE only
//to get TextView visibility
mFab.getFabTextVisibility();//returns Int
mFab.setFabTypeface(typeface);//to change text font
//in kotlin use can directly access fabText visibility by
mFab.fabTextVisibility = View.VISIBLE
If your project do not have kotlin support follow these steps
Step 1: Add Jitpack kotlin gradle plugin in your root build.gradle file (not your module build.gradle file):
buildscript {
//this
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
...
//and this line
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
To more info and latest version refer this
Step 2: Apply plugins to your module's build.gradle file:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
...