如何检查应用程序是否在多窗口中

如何检查应用程序是否在多窗口中

本文介绍了如何在Android N中更改多窗口显示的视图?如何检查应用程序是否在多窗口中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为多个窗口"提供单独的布局或单独的活动?

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

例如我已经在android开发者网站的帮助下检查了以下内容

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 ?

推荐答案

来自 Android开发人员链接.

要在多窗口激活中使用的UI或单独的布局进行更改.

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

  • 从活动Activity.isInMultiWindowMode()中调用以查明该活动是否处于多窗口模式.
  • 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);

也可以使用inMultiWindow()替换片段

  • 要在多窗口激活中获得回调.

From Activity onMultiWindowChanged方法可用于处理此方法回调上的运行时更改.只要活动进入或退出具有boolean值的多窗口模式,系统都会在此方法上进行回调. a href ="https://github.com/googlesamples/android-MultiWindowPlayground/blob/master/Application/src/main/java/com/android/multiwindowplayground/activities/LoggingActivity.java" rel ="nofollow noreferrer">示例链接& android开发者链接

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.

这篇关于如何在Android N中更改多窗口显示的视图?如何检查应用程序是否在多窗口中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:55