Reputation: 3710
I am trying to set the dialog to the bottom but couldn't able to do that. It showing the top of the page.
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="370dp"
android:background="@android:color/transparent"
xmlns:tools="http://schemas.android.com/tools"
android:padding="8dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/cv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="4dp"
app:cardElevation="1dp"
app:cardUseCompatPadding="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<android.support.constraint.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="wrap_content">
<TextView
android:id="@+id/textView14"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorSecondaryBackground"
android:fontFamily="@font/gotham_medium_regular"
android:padding="8dp"
android:text="Send Promotions"
android:textColor="@color/colorSecondaryText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="@+id/promotionDataLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/two_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textView14">
<android.support.v7.widget.RecyclerView
android:id="@+id/promotionList"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@id/guidelineEnd"
app:layout_constraintStart_toStartOf="@id/guidelineStart"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.RecyclerView>
<android.support.constraint.Guideline
android:id="@+id/guidelineStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.08" />
<android.support.constraint.Guideline
android:id="@+id/guidelineEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.92" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.v7.widget.CardView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabDone"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/red_plus"
app:layout_anchor="@+id/cv1"
app:elevation="1dp"
app:backgroundTint="@android:color/white"
app:layout_anchorGravity="center|bottom" />
</android.support.design.widget.CoordinatorLayout>
I am creating the dialog class like that:
class PromotionDialog:Dialog{
var mContext:Context?=null
constructor(context: Context) : super(context) {}
constructor(context: Context, themeResId: Int) : super(context, themeResId) {
mContext=context
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.promotion_layout)// use your layout in place of this.
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT));
}
}
Solution Tried:
I can't use bottomsheetdialog due to design constraint.
EDIT: I am calling the dialog like this
val promotionDialog= PromotionDialog(this@DashboardActivity, android.R.style.Theme_Material_Light_NoActionBar_Fullscreen)
promotionDialog.show()
EDIT 2:
As @RAJA suggested, It was because of the FUll screen theme.
So now I have change the theme to :
<style name="ThemeDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowMinWidthMajor">100%</item>
<item name="android:windowMinWidthMinor">100%</item>
<item name="android:windowIsFloating">true</item>
</style>
But still there are some margin in the bottom
Upvotes: 4
Views: 5077
Reputation: 2815
You can try like this :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.promotion_layout)// use your layout in place of this.
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT));
val windowlp = window.attributes
windowlp.gravity = Gravity.BOTTOM
window.attributes = windowlp
}
Access your dialog view in your Activity
PromotionDialog(this).show();
Upvotes: 4