How to Android dialog (fullscreen, embedded) as in Google Calendar app
Asked Answered
T

0

11

What I'd like to achive

A small/large screen behavior as it is implemented by Google in its Calendar app.

For example when you create a new event, on a large screen a 'dialog' opens

  1. that darkens the Activity in the background
  2. the Toolbar always stays at the same location and never gets pushed out of view by the on-screen keyboard
  3. in portrait mode the bottom of the dialog's Toolbar is aligned with the bottom of the Activity's 'extended' toolbar.

    Toolbar alignment w/ Activity Toolbar

    The Contextual Action Bar (e.g. for text selection) is drawn over the Toolbar of the Activity, and pushes the dialog down, so it's not anchored with the Activity's Toolbar anymore.

  4. in landscape mode it seems to be anchored below the notification bar; the Contextual Action Bar is drawn over the Toolbar of the Activity

    Contextual Action Bar: left landscape, right portrait

on a small screen,

  1. the dialog fills the screen
  2. the Contextual Action Bar gets drawn over the Toolbar

What I've tried so far

A. fullscreen DialogFragment expample from the android documentation (can't add anymore links b/c of a lack of reputation)

  • when displayed as fullscreen dialog, the background is transparent, and it draws over the notification bar (similar to immersive mode)

B. added (thanks to some posts on stackoverflow)

  • dialog fragment styles:

    setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialogFragmentStyle);
    
    <style name="MyDialogFragmentStyle" parent="@style/MyTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowIsFloating">false</item>
    </style>
    
  • removed the window title

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    
  • added a custom toolbar

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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="match_parent" >
    
      <android.support.v7.widget.Toolbar
         android:id="@+id/toolbar"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="?attr/colorPrimary"
         android:minHeight="?attr/actionBarSize"
         app:homeAsUpIndicator="@drawable/ic_arrow_back_white_24dp"
         app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    
      <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar" >
      </FrameLayout>
    
    </RelativeLayout>
    
  • and set the dialog to fullscreen on small devices

    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    

and this kinda works, it solves some of my What I'd like to achive points and A. 'the Android sample' problems (transparent background, ...)

  1. darkens the Activity in the backgound

    • works
  2. the Toolbar always stays at the same location and never gets pushed out of view by the on-screen keyboard

    • kinda, with the exception of the Toolbar being pushed out of screen by the on-screen keyboard
  3. in portrait mode the bottom of the dialog Toolbar is aligned with the bottom of the Activity's 'extended/large' Toolbar. The Contextual Action Bar (e.g. for text selection) is drawn over the Toolbar of the Activity, and pushes the dialog down, so it's not anchored with the Activity's Toolbar anymore.

    • nope, didn't put any effort into alignment b/c of 2. The Contextual Action Bar is drawn over the Activity's Toolbar and over part of the dialog's Toolbar.
  4. in landscape mode it seems to be anchored below the notification bar; the Contextual Action Bar is drawn over the Toolbar of the Activity.

    • nope, on-screen keyboard pushes the Toolbar out of screen and the Contextual Action Bar is drawn over the Activity's Toolbar, but also over part of the dialog (b/c of the dialog's Toolbar being pushed outside - I suppose)
  5. it fills the screen

    • works
  6. the Contextual Action Bar gets drawn over the dialog's Toolbar

    • the Contextual Action Bar pushes the dialog's Toolbar down, leaving the user with two toolbars. Looks weird, but at least it's functional.

So, my first post got a bit lenghty - thanks to all who read along so far.

I've been researching this subject on and off for quite some time now. Some people say dialog fragments are no good for non-fullscreen display and that one should style an activity to look like a dialog. Others say it's bad practice to style activities to look like dialogs b/c that's what DialogFragments were made for. There doesn't seem to be a broad agreement on this topic.

Does anyone have any insight on how Google implemented this in it's Calendar app? (Sadly in the AOSP sources, only the old calendar app is available).

And is there a way to meet all my requirements with dialog fragments?

Thanks a lot Michael

btw: Large device tests on a Android 4.1 tablet, small device Android 4.1 and 5.0, using Support Library DialogFragment, but in the transition to 'normal' DialogFragment.

Tyndall answered 31/12, 2015 at 10:41 Comment(3)
I think it might be using an Activity as a Dialog, but I'm not sure. developer.android.com/guide/topics/ui/…Rapp
Or maybe this: developer.android.com/guide/topics/ui/…Rapp
The page you linked was the starting point for my 'research'. Styling an activity as a dialog seems to be the way to go if you don't want to convert all your existing Activities into Fragments "Which approach you choose depends on your app design, but showing an activity as a dialog is often useful when your app is already designed for small screens and you'd like to improve the experience on tablets.." "Showing a Dialog Fullscreen or as an Embedded Fragment" is what I did b/c, well it seemed to me that Fragments are the 'fancy new thing' that everyone is supposed to use.Tyndall

© 2022 - 2024 — McMap. All rights reserved.