Skip to content

Instantly share code, notes, and snippets.

@kuwapa
Created April 3, 2020 04:05
Show Gist options
  • Save kuwapa/24521053de2ae7421e177b865492e625 to your computer and use it in GitHub Desktop.
Save kuwapa/24521053de2ae7421e177b865492e625 to your computer and use it in GitHub Desktop.
How to create an transparent alert dialog at bottom of screen with icon sticking out. Like this - https://imgur.com/a/PcEOEbJ
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@color/md_blue_grey_600"
android:paddingTop="45dp">
<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="@font/medium_font"
android:text="Enjoying App?"
android:textColor="@color/white"
android:textSize="20sp" />
<TextView
android:id="@+id/descTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titleTextView"
android:layout_centerHorizontal="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:fontFamily="@font/regular_font"
android:gravity="center"
android:text="Recommend Android dev to your friends cuz you shouldn't suffer alone"
android:textColor="@color/white"
android:textSize="15sp" />
<TextView
android:id="@+id/notNotButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/descTextView"
android:layout_alignBottom="@+id/rateAppTextView"
android:layout_marginTop="32dp"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@+id/rateAppTextView"
android:background="?selectableItemBackground"
android:fontFamily="@font/medium_font"
android:gravity="center"
android:padding="8dp"
android:text="Not Now"
android:textColor="@color/accent" />
<Button
android:id="@+id/rateAppTextView"
style="@style/Widget.MaterialComponents.Button.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/descTextView"
android:layout_alignParentRight="true"
android:layout_marginTop="32dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:fontFamily="@font/medium_font"
android:text="Rate App"
android:textColor="@color/black"
android:textSize="13sp" />
</RelativeLayout>
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher_512" />
</RelativeLayout>
override fun showNpsDialog() {
val builder = AlertDialog.Builder(this, R.style.NpsDialogStyle)
builder.setTitle(null)
builder.setMessage(null)
builder.setView(R.layout.dialog_nps)
builder.setCancelable(false)
val dialog = builder.create()
val window = dialog.window
/*
This is to set the background of the dialog transparent so that the icon shows up half outside
the dialog
*/
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
//This is to set the dialog at the bottom of the screens
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
val wlp = window?.attributes
wlp?.gravity = Gravity.BOTTOM
window?.attributes = wlp
dialog.setOnShowListener {
val rateAppButton = dialog.findViewById<Button>(R.id.rateAppTextView)!!
val notNowButton = dialog.findViewById<TextView>(R.id.notNotButton)!!
rateAppButton.setOnClickListener {
//TODO take to play store
dialog.dismiss()
}
notNowButton.setOnClickListener {
//TODO add logic to show dialog to user later
dialog.dismiss()
}
}
dialog.show()
}
<style name="NpsDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment