Android Dialog横向铺满
2017-06-21 本文已影响0人
Jarhot
public class HorizontalDialog extends Dialog {
public HorizontalDialog(@NonNull Context context) {
super(context, R.style.Horizontal_Dialog);
init();
}
public HorizontalDialog(@NonNull Context context, View view) {
super(context, R.style.Horizontal_Dialog);
setContentView(view);
init();
}
public HorizontalDialog(@NonNull Context context, View view, @StyleRes int themeResId) {
super(context, themeResId);
setContentView(view);
init();
}
private void init() {
WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
windowManager.getDefaultDisplay().getSize(point);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = (point.x);
params.gravity = Gravity.TOP;
getWindow().setBackgroundDrawableResource(R.color.white);
getWindow().setAttributes(params);
}
}
<style name="Horizontal_Dialog" parent="Theme.AppCompat.Light">
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:colorBackground">?attr/colorBackgroundFloating</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowTitleStyle">@style/RtlOverlay.DialogWindowTitle.AppCompat</item>
<item name="android:windowTitleBackgroundStyle">@style/Base.DialogWindowTitleBackground.AppCompat</item>
<item name="android:windowBackground">@drawable/abc_dialog_material_background</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@style/Animation.AppCompat.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="listPreferredItemPaddingLeft">0dip</item>
<item name="listPreferredItemPaddingRight">0dip</item>
<item name="android:listDivider">@null</item>
<item name="windowFixedWidthMajor">100%</item>
<item name="windowFixedWidthMinor">100%</item>
<item name="windowFixedHeightMajor">@null</item>
<item name="windowFixedHeightMinor">@null</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>