avast / android-styled-dialogs

Backport of Material dialogs with easy-to-use API based on DialogFragment
Apache License 2.0
2.15k stars 450 forks source link

Dialogs width on Tablets #110

Closed martarodriguezm closed 9 years ago

martarodriguezm commented 9 years ago

Using this library when I show a dialog on tablet its width always matches parent, but I don't want it always. When using simple dialogs I just want a small dialog.

davidvavra commented 9 years ago

Can you attach a screenshot? Do native dialogs on Lollipop behave differently?

martarodriguezm commented 9 years ago

It is a Samsung Galaxy Tab 4 with Android 4.4.2 device-2015-03-16-134737

Yes, it is very common to have a "small" dialog just in the middle of the screen.

martarodriguezm commented 9 years ago

Finally I have override the styles to fix the issue for tablets and it works fine also on mobile:

    <style name="SDL.Layout">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:orientation">vertical</item>
    </style>

    <style name="SDL.ScrollView">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="SDL.TextView.Title">
        <item name="android:textSize">20sp</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:textColor">?sdlTextPrimaryColor</item>
        <!-- paddings set in code -->
    </style>

    <style name="SDL.Layout.Buttons">
        <item name="android:orientation">horizontal</item>
        <item name="android:layout_height">@dimen/grid_12</item>
        <item name="android:gravity">center_vertical</item>
        <item name="android:layout_gravity">right</item>
        <item name="android:paddingLeft">0dp</item>
        <item name="android:paddingRight">0dp</item>
    </style>

    <style name="SDL.Expander">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">0dp</item>
    </style>
davidvavra commented 9 years ago

I have checked native dialogs on Lollipop and they indeed have some smaller width on tablet's landscape orientation. We will fix that in the next version of the library or we will accept a pull request.

@marta-rodriguez Your solution is not correct, dialogs on Lollipop are not 'wrap_content' but they have some minimal width. The exact value must be found in Android source code.

martarodriguezm commented 9 years ago

Yes, you are right. I have been working on it again and the problem is with the "Expander" for the buttons, it makes the dialog always "match_parent" so it is too big for tablets. With stacked buttons it works perfect also for tablets. I'm trying to fix it.

davidvavra commented 9 years ago

@marta-rodriguez When you fix it, please send a pull request. Maybe it would be good idea to ditch Expander and replace it with RelativeLayout positioning for buttons.

martarodriguezm commented 9 years ago

I have sent you a pull request