Search code examples
androidandroid-intentandroid-activityandroid-7.0-nougatandroid-n-preview

How to change view for multiple window display in Android N? How to check application is in multiwindow or not?


How can we give separate layout or separate activity for Multiple window ?

eg. I have checked below things with help of android developer site

<activity android:name="com.configure.it.MyScreen">
    <layout android:defaultHeight="400dp"
          android:defaultWidth="200dp"
          android:gravity="top|end"
          android:minimalSize="300dp" />
</activity>

by declaring above things it affect how an activity behaves in multi-window mode.

But how can I show different layout if my particular screen is activated on Multiple-Window ?


Solution

  • From the Android Developer link .

    To make changes in UI or separate layout which should be used on Multiple-window activate.

    We can check if activity is in Multiple-window by following way

    • From activity Activity.isInMultiWindowMode() Call to find out if the activity is in multi-window mode.

    eg. To check in Activity if its multiple window than header(or any view should have Red background color if its not in multiple window thn it should be Green background color)

    headerView.setBackgroundColor(inMultiWindow()?Color.RED:Color.GREEN);
    

    using inMultiWindow() replacing Fragment is also possible

    • To get Callback on Multiple-Window Activation.

    From Activity onMultiWindowChanged method is available to handle runtime changes on this method callback.System will give callback on this method whenever the activity goes into or out of multi-window mode with boolean value.With the help of sample link & android developer link

    @Override
    public void onMultiWindowChanged(boolean inMultiWindow) {
        super.onMultiWindowChanged(inMultiWindow);
        headerView.setBackgroundColor(inMultiWindow ? Color.RED : Color.GREEN);
        // here we can change entire fragment also.
        //If multiple window in than seperate and for multiple window out different
    
    }
    

    Will keep updating if I get anything else.