0

I've an activity which uses this BottomSheetDialog theme:

<activity
    android:name=".login.LoginActivity"
    android:configChanges="orientation|keyboardHidden"
    android:theme="@style/Theme.MaterialComponents.BottomSheetDialog"
    android:screenOrientation="portrait" />

The activity layout is:

<androidx.coordinatorlayout.widget.CoordinatorLayout 
    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="@android:color/transparent"
    tools:context=".login.LoginActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:background="@color/red"
        android:layout_gravity="bottom"
        android:gravity="bottom"/>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

The red button appears in the middle of the screen. I can't figure out how to align it to the bottom of the screen.

=================

     UPDATE

=================

I tried to open a new project and same problem (red button appears in the middle of the screen)

activity_main:

<?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="@android:color/transparent">

<Button
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    android:background="@color/teal_200"
    android:layout_gravity="bottom"
    android:gravity="bottom"/>

</androidx.constraintlayout.widget.ConstraintLayout>

manifest:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MyApplication">
    <activity android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden"
        android:theme="@style/Theme.MaterialComponents.BottomSheetDialog"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

build.gradle

implementation 'com.google.android.material:material:1.4.0-alpha02'
Erez git
  • 73
  • 8

1 Answers1

0

SOLVED!

I just added:

Window window = getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);

in the activity onCreate()

Erez git
  • 73
  • 8