2 years ago

#42458

test-img

user1063364

Android 12 - full screen Activity breaks Dialog layout with ScrollView

I have simple activity with button. If I press this button then I show dialog with fixed panel on bottom and scrollable content above. Here is how it looks:

enter image description here

android.app.Dialog d = new android.app.Dialog(this);
d.setContentView(R.layout.dialog);

d.findViewById(R.id.confirm).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        showMsg();
    }
});


d.show();

However, I need full screen activity. I defined my own theme and applied it in AndroidManifest.xml

<activity android:name=".MainActivity"
    android:exported="true"
    android:resizeableActivity="true"
    android:theme="@style/Theme.NoBackground">

Thema definition:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.NoBackground" parent="android:Theme.NoTitleBar.Fullscreen">
        <item name="android:windowBackground">@null</item>
        <!--<item name="android:windowSwipeToDismiss">false</item>-->
    </style>
</resources>

After that is the dialog's layout broken and I see this:

enter image description here

There appears empty space on top of dialog. This I fixed after inheriting from Dialog and fixing constructor this way:

public class MyDialog extends Dialog {
    public MyDialog(Context context)
    {
        super(context);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        if (Build.VERSION.SDK_INT < 18) {
            return;
        }

        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

}

However, bottom bar is still missing. Is invisible. It exists and is placed correctly, but is invisible. If I tap on the place where should be button "OK" then I see correctly Toast message.

I must say, inherited MyDialog with full screen activity correctly works up to android 12. It is broken since android 12. Can someone help me to fix it?

Here is how looks the layout for dialog:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="270dp"
    android:orientation="vertical" >
    <ScrollView
        android:id="@+id/button_menu_mainscrollview"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" >
        <LinearLayout
            android:id="@+id/button_menu_mainview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="5dp" >

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button1" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button2" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button3" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button4" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button5" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button6" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button7" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button8" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button9" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button10" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button11" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button12" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button13" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button14" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button15" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button16" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button17" />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button18" />
        </LinearLayout>
    </ScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp" >

        <Button
            android:id="@+id/confirm"
            android:layout_width="80dp"
            android:layout_height="35dp"
            android:layout_centerHorizontal="true"
            android:scaleType="centerInside"
            android:text="OK"/>

    </RelativeLayout>

</LinearLayout>

I attached link to simple example for android studio - here.

android

android-layout

dialog

fullscreen

0 Answers

Your Answer

Accepted video resources