美文网首页
Android Dialog横向铺满

Android Dialog横向铺满

作者: Jarhot | 来源:发表于2017-06-21 18:24 被阅读0次
    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>
    

    相关文章

      网友评论

          本文标题:Android Dialog横向铺满

          本文链接:https://www.haomeiwen.com/subject/awutcxtx.html