Java Code Examples for android.view.Window#setBackgroundDrawableResource()

The following examples show how to use android.view.Window#setBackgroundDrawableResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PublisherCountdownDialogFragment.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    Window window = getDialog().getWindow();
    window.setLayout((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, WIDTH,
            getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, WIDTH,
                    getResources().getDisplayMetrics()));
    window.setGravity(Gravity.CENTER);

    // Transparent background; see http://stackoverflow.com/q/15007272/56285
    // (Needed to make dialog's alpha shadow look good)
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}
 
Example 2
Source File: AbstractAlertDialog.java    From DMusic with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a dialog window that uses a custom dialog style.
 *
 * @param context    Context
 * @param themeResId The dialog's layout resource
 * @param isSetWin   Set the gravity of the window
 * @param gravity    The desired gravity constant
 * @param width      The dialog's width
 * @param heith      The dialog's height
 */
protected AbstractAlertDialog(@NonNull Context context, @StyleRes int themeResId, boolean isSetWin, int gravity, int width, int heith) {
    super(context, themeResId);
    this.mContext = context;
    this.mRootView = LayoutInflater.from(context).inflate(getLayoutRes(), null);
    setContentView(this.mRootView);
    setCanceledOnTouchOutside(true);
    setCancelable(true);
    if (isSetWin) {
        Window dialogWindow = getWindow();
        if (dialogWindow != null) {
            dialogWindow.setWindowAnimations(-1);
            dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
            dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
            dialogWindow.setGravity(gravity);
            // Get the current layout param of the dialog
            WindowManager.LayoutParams p = dialogWindow.getAttributes();
            // Set dialog's width
            p.width = width;
            // Set dialog's height
            p.height = heith;
            dialogWindow.setAttributes(p);
        }
    }
    init(this.mRootView);
}
 
Example 3
Source File: InvitedDialogFragment.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    Window window = getDialog().getWindow();
    window.setLayout((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, WIDTH,
            getResources().getDisplayMetrics()), ViewGroup.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.CENTER);

    // Transparent background; see http://stackoverflow.com/q/15007272/56285
    // (Needed to make dialog's alpha shadow look good)
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}
 
Example 4
Source File: ShareSelectionDialog.java    From apkextractor with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog_share_function);
    Window window=getWindow();
    if(window!=null){
        WindowManager.LayoutParams layoutParams=window.getAttributes();
        layoutParams.gravity= Gravity.BOTTOM;
        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height=WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(layoutParams);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setWindowAnimations(R.style.DialogAnimStyle);
    }
    findViewById(R.id.dialog_share_direct).setOnClickListener(this);
    findViewById(R.id.dialog_share_system).setOnClickListener(this);
    findViewById(R.id.dialog_share_cancel).setOnClickListener(this);
}
 
Example 5
Source File: InputDialogFragment.java    From ChatRecyclerView with MIT License 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Window window = getDialog().getWindow();
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}
 
Example 6
Source File: ViewUtils.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
public static void setupWindowFlagsForStatusbarOverlay(Window window, boolean setBackgroundResource) {

        if (MizLib.isKitKat()) {
            // If we're running on KitKat, we want to enable
            // the translucent status bar
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        if (MizLib.hasKitKat()) {
            // If we're running on KitKat or above, we want to show
            // the background image beneath the status bar as well.
            window.getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }

        // Make the status bar color transparent to begin with
        if (MizLib.hasLollipop())
            window.setStatusBarColor(Color.TRANSPARENT);

        // If requested, set a background resource on the Window object
        if (setBackgroundResource)
            window.setBackgroundDrawableResource(R.drawable.bg);
    }
 
Example 7
Source File: Shake2Share.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 8
Source File: ThemeDialog.java    From Elephant with Apache License 2.0 5 votes vote down vote up
private void initContentView() {
    View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_theme, null);

    Rect displayRectangle = new Rect();
    Window window = getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);
    view.setMinimumWidth((int)(displayRectangle.width() * 0.8f));
    window.setBackgroundDrawableResource(R.color.dialog_bg);

    setContentView(view);

    view.findViewById(R.id.theme_blue).setOnClickListener(this);
    view.findViewById(R.id.theme_gray).setOnClickListener(this);
    view.findViewById(R.id.theme_white).setOnClickListener(this);
}
 
Example 9
Source File: Shake2Share.java    From AndroidLinkup with GNU General Public License v2.0 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 10
Source File: LauncherActivity.java    From Last-Launcher with GNU General Public License v3.0 5 votes vote down vote up
private void renameApp(String activityName, String appName) {
    dialogs = new RenameInputDialogs(this, activityName, appName, this);
    Window window = dialogs.getWindow();
    if (window != null) {
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    }

    dialogs.show();

}
 
Example 11
Source File: BaseDialogFragment.java    From AndroidPlayground with MIT License 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    // without title and title divider

    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    Window window = getDialog().getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    //CHECKSTYLE:OFF
    params.dimAmount = getDimAmount(); // dim only a little bit
    //CHECKSTYLE:ON
    window.setAttributes(params);

    window.setLayout(getWidth(), getHeight());
    window.setGravity(getGravity());

    // Transparent background; see http://stackoverflow.com/q/15007272/56285
    // (Needed to make dialog's alpha shadow look good)
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}
 
Example 12
Source File: ArticleShareDialogFragment.java    From MaoWanAndoidClient with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Window window = getDialog().getWindow();
    window.setBackgroundDrawableResource(android.R.color.transparent);
    //设置软键盘弹出模式 防止遮挡Dialog
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
 
Example 13
Source File: CollectionDialogFragment.java    From MaoWanAndoidClient with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Window window = getDialog().getWindow();
    window.setBackgroundDrawableResource(android.R.color.transparent);
    //设置软键盘弹出模式 防止遮挡Dialog
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
 
Example 14
Source File: AbstractDialog.java    From DMusic with Apache License 2.0 5 votes vote down vote up
protected AbstractDialog(Context context, int themeResId, ViewGroup.LayoutParams params) {
    super(context, themeResId);
    this.mContext = context;
    this.mRootView = LayoutInflater.from(context).inflate(getLayoutRes(), null);
    setContentView(this.mRootView, params);
    setCanceledOnTouchOutside(true);
    setCancelable(true);
    Window dialogWindow = getWindow();
    if (dialogWindow != null) {
        dialogWindow.setWindowAnimations(-1);
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
    }
    init(this.mRootView);
}
 
Example 15
Source File: Shake2Share.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 16
Source File: Shake2Share.java    From ShareSDKShareDifMsgDemo-Android with MIT License 5 votes vote down vote up
public void setActivity(Activity activity) {
	super.setActivity(activity);
	int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
	if (resId > 0) {
		activity.setTheme(android.R.style.Theme_Dialog);
		activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window win = activity.getWindow();
		win.setBackgroundDrawableResource(resId);
	}
}
 
Example 17
Source File: BaseDialog.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public void setDialogWindowBgRes(@DrawableRes int bgResId) {
    Window dialogWindow = getWindow();
    if (dialogWindow != null) {
        dialogWindow.setBackgroundDrawableResource(bgResId);
    }
}
 
Example 18
Source File: ImageScannerDialog.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public void show(ShowImageDialogResult result) {

        if (mDialog != null && mDialog.isShowing()) {
            return;
        }
        if (!checkPermission(result)) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        mDialog = builder.create();
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDialog.show();
        mImageScannerDialogLayout = new ImageScannerDialogLayout(mContext);
        mImageScannerDialogLayout.setBackgroundColor(Color.WHITE);
        mImageScannerDialogLayout.mDismissDialogListener = new IWidgetClickListener() {
            @Override
            public void onClick(@Nullable Object o) {
                dismiss();
            }
        };
        mImageScannerDialogLayout.mCropImageResultListener = new IWidgetClickListener<String>() {
            @Override
            public void onClick(@Nullable String imgPath) {
                if (mCropImageResultListener != null) {
                    mCropImageResultListener.onClick(imgPath);
                }
                dismiss();
            }
        };
        //设置dialog全屏幕
        Window window = mDialog.getWindow();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.getDecorView().setPadding(0, 0, 0, 0);
        window.setGravity(Gravity.CENTER);
        window.setContentView(mImageScannerDialogLayout);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(lp);
        if (result != null) {
            result.successful();
        }
    }
 
Example 19
Source File: WindowAdjuster.java    From DialogUtil with Apache License 2.0 4 votes vote down vote up
private static void setBackground(Window window, ConfigBean bean) {

        if(!bean.showAsActivity && bean.bgRes != 0){
            window.setBackgroundDrawableResource(bean.bgRes);
        }
        //no need to modify the background
       /* if((bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_GRID && bean.hasBehaviour)
                || bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_LIST
                || bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_CUSTOM
                || bean.type == DefaultConfig.TYPE_PROGRESS){
            // No need to set backgroud
            return;
        }

        if (bean.alertDialog!= null){
            if(bean.useTheShadowBg){
                window.setBackgroundDrawableResource(R.drawable.shadow);
            }else {
                if(bean.bgRes>0)
                    window.setBackgroundDrawableResource(bean.bgRes);
                else {
                    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                }

            }
        }else {
            if(bean.type == DefaultConfig.TYPE_IOS_LOADING  ){//转菊花时,背景透明
                window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            }else if((bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_GRID && !bean.hasBehaviour)){
                window.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
            }else {
                if(bean.useTheShadowBg){
                    window.setBackgroundDrawableResource(R.drawable.shadow);
                }else {
                    if(bean.bgRes>0)
                        window.setBackgroundDrawableResource(bean.bgRes);
                    else {
                        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    }
                }
            }

        }*/
    }
 
Example 20
Source File: CardVerificationProgressScreen.java    From Luhn with MIT License 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Window window = getDialog().getWindow();
    window.setBackgroundDrawableResource(android.R.color.transparent);
}