下面列出了android.view.Window#setBackgroundDrawableResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
@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));
}
}
}
@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));
}
}
}
@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);
}
@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));
}
}
}
/**
* 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);
}
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();
}
@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));
}
}
}
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);
}
}
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);
}
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);
}
}
@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);
}
@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);
}
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);
}
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);
}
}
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);
}
}
public void setDialogWindowBgRes(@DrawableRes int bgResId) {
Window dialogWindow = getWindow();
if (dialogWindow != null) {
dialogWindow.setBackgroundDrawableResource(bgResId);
}
}
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();
}
}
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));
}
}
}
}*/
}
@Override
public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
}