最近需要用点dialog

恰好需要用到一点dialog,然后在google的android官网上看到建议使用DialogFragment,然后,按照他的demo做出来的效果并不是全屏。
如是查找api发现:setStyle是可以控制DialogFragment显示样式的。

但是这个api调用,必须是在onCreate方法里面,

/** * Call to customize the basic appearance and behavior of the * fragment's dialog.  
This can be used for some common dialog behaviors, * taking care of selecting flags, theme, and other options for you.  
The * same effect can be achieve by manually setting Dialog and Window * attributes yourself.  
Calling this after the fragment's Dialog is * created will have no effect. 
* * @param style Selects a standard style: may be {@link #STYLE_NORMAL},
 * {@link #STYLE_NO_TITLE}, {@link #STYLE_NO_FRAME}, or * {@link #STYLE_NO_INPUT}. 
* @param theme Optional custom theme.  If 0, an appropriate theme (based * on the style) will be selected for you. 
*/
public void setStyle(@DialogStyle int style, @StyleRes int theme) {    
  mStyle = style;   
if (mStyle == STYLE_NO_FRAME || mStyle == STYLE_NO_INPUT) {
        mTheme = android.R.style.Theme_Panel;   
 }
if (theme != 0) { 
       mTheme = theme;
    }
}


全屏 ,连statusBar都消失掉

setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Light_NoTitleBar_Fullscreen);

全屏 ,statusBar还在

setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);

参数,第一个参数我是随便给的,因为根据api源码可以看到,如果第二个参数不为0,那么第一个参数是没有作用的,会覆盖,具体的样式还有很多,甚至可以自己定制都是没问题的。

你可能感兴趣的:(最近需要用点dialog)