主要类:Presentation、DisplayManager、Display
1.如何获取设备上的屏幕?
DisplayManager mDisplayManager;//屏幕管理类
Display[] displays;//屏幕数组
mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
displays =mDisplayManager.getDisplays();
2.主屏和副屏的区分?
主屏:displays[0]
副屏:displays[1]
3.如何在副屏上展示内容?
通过Presentation来实现,Presentation继承了Dialog。假设我们写了一个DifferentDislay的类,这个类是要继承
Presentation类的。代码:
privateclass DifferentDislay extends Presentation{
public DifferentDislay(Context outerContext, Display display) {
super(outerContext,display);
//TODOAuto-generated constructor stub
}
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.diffrentdisplay_basket);
}
}
4.开启副屏
//context用getApplicationContext在点击home键时只要程序还在后台副屏就还显示,displays[1]是副屏
DifferentDislay mPresentation = new DifferentDislay (
getApplicationContext,displays[1]);
//setType()中的参数可以使用TYPE_SYSTEM_ALERT,TYPE_TOAST,不过俩个都过时了;
//介意过时的话可以改成FLA_LAYOUT_IN_OVERSCAN;
mPresentation.getWindow().setType(
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
mPresentation.show();
副屏幕不随主屏幕退出可以参考http://blog.csdn.net/u014122493/article/details/68927306