try {
WindowManager manager = getWindowManager();
Field mGlobal_field = manager.getClass().getDeclaredField("mGlobal");
mGlobal_field.setAccessible(true);
Object managerGlobal = mGlobal_field.get(manager);
//noinspection ConstantConditions
Field mViews_field = managerGlobal.getClass().getDeclaredField("mViews");
mViews_field.setAccessible(true);
//noinspection unchecked
ArrayList<View> mViews = (ArrayList<View>) mViews_field.get(managerGlobal);
//noinspection ConstantConditions
View dialogDecorView = mViews.get(mViews.size() - 1);// TODO 这里需要做一下判断,是不是dialog的decorView
WindowManager.LayoutParams params = (WindowManager.LayoutParams) dialogDecorView.getLayoutParams();
params.gravity = Gravity.TOP;
dialogDecorView.setLayoutParams(params);
manager.removeView(dialogDecorView);
manager.addView(dialogDecorView, params);
} catch (Exception e) {
e.printStackTrace();
}
try {
WindowManager manager = getWindowManager();
Field mGlobal_field = manager.getClass().getDeclaredField("mGlobal");
mGlobal_field.setAccessible(true);
Object managerGlobal = mGlobal_field.get(manager);
//noinspection ConstantConditions
Field mViews_field = managerGlobal.getClass().getDeclaredField("mViews");
mViews_field.setAccessible(true);
//noinspection unchecked
ArrayList<View> mViews = (ArrayList<View>) mViews_field.get(managerGlobal);
//noinspection ConstantConditions
View dialogDecorView = mViews.get(mViews.size() - 1);// TODO 这里需要做一下判断,是不是dialog的decorView
WindowManager.LayoutParams params = (WindowManager.LayoutParams) dialogDecorView.getLayoutParams();
params.gravity = Gravity.TOP;
dialogDecorView.setLayoutParams(params);
manager.removeView(dialogDecorView);
manager.addView(dialogDecorView, params);
} catch (Exception e) {
e.printStackTrace();
}
try { WindowManager manager = getWindowManager(); Field mGlobal_field = manager.getClass().getDeclaredField("mGlobal"); mGlobal_field.setAccessible(true); Object managerGlobal = mGlobal_field.get(manager); //noinspection ConstantConditions Field mViews_field = managerGlobal.getClass().getDeclaredField("mViews"); mViews_field.setAccessible(true); //noinspection unchecked ArrayList<View> mViews = (ArrayList<View>) mViews_field.get(managerGlobal); //noinspection ConstantConditions View dialogDecorView = mViews.get(mViews.size() - 1);// TODO 这里需要做一下判断,是不是dialog的decorView WindowManager.LayoutParams params = (WindowManager.LayoutParams) dialogDecorView.getLayoutParams(); params.gravity = Gravity.TOP; dialogDecorView.setLayoutParams(params); manager.removeView(dialogDecorView); manager.addView(dialogDecorView, params); } catch (Exception e) { e.printStackTrace(); }