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

穿精又带淫゛_ 提交于 2019-12-10 10:01:46

问题


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 ?


回答1:


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.




回答2:


isInMultiWindowMode() is added in API 24 to check device is in Multi window Mode or not, it returns a boolean value. whenever device goes to Multi window Mode it triggers onConfigurationChanged() method.

you will need to manually update your Views, Reload resources, etc... in onConfigurationChanged() based on Landscape and portrait mode.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
     if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
      {
        //do something (Update your views / Reload resources)
      }else{

      }
}

In Manifest.xml

 <activity
   android:name=".yourActivity"
   android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
 />

For further reference check with Multi-Window Support Google Dev and MultiWindow Medium Corp



来源:https://stackoverflow.com/questions/36098550/how-to-change-view-for-multiple-window-display-in-android-n-how-to-check-applic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!