1、消除android的标题和状态栏
方式一:
// 去除title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 去掉Activity上面的状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
注意:在这里要强调一点,设置全屏的俩段代码必须在setContentView(R.layout.main)
之前,不然会报错。
方式二:
在AndroidManifest.xml配置文件中为对应的Activity设置
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
2、获取窗口大小并设置新的宽和高
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //获取屏幕宽、高
LayoutParams p =getWindow().getAttributes(); //获取对话框当前的参数值
p.height = (int)(d.getHeight() * 0.9); //高度设置为屏幕的0.9
p.width = (int) (d.getWidth() *0.8); //宽度设置为屏幕的0.8
getWindow().setAttributes((android.view.WindowManager.LayoutParams) * p);
p.alpha = 1.0f; //设置本身透明度 p.dimAmount = 0.0f; //设置黑暗度
3、消除窗口的背景色,比如一个activity一个对话框的形式出现,四周会出现默认背景色,消除的方法如下:
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));// 消除图片背景