首页 > 代码库 > Android:dialog去除边框的实现(自带Style的padding)

Android:dialog去除边框的实现(自带Style的padding)

   public void show(View view) {

        
        MyDialog myDialog=new MyDialog(MainActivity.this);
        myDialog.show();
//需要设置属性,否则dialog的大小不起作用!必须先show再set属性
        WindowManager.LayoutParams params = myDialog.getWindow().getAttributes();
        params.width = 600;
        params.height = 300;
        View view1 = View.inflate(getApplicationContext(), R.layout.dialogview, null);
//设置位置的属性
        Window dialogWindow = myDialog.getWindow();
//        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);

        // 必须使用这个方法,不能使用dialog.setView()的方法
        myDialog.getWindow().setContentView(R.layout.dialogview);
        dialogWindow.setAttributes(params);

    }

----------------------------------------------------------------------------------------------------------------------
public class MyDialog extends Dialog {
public MyDialog(Context context) {
super(context,R.style.ShareDialog);
}
}
-------------------------------------------------------------------------------------------------------------------------
<style name="ShareDialog"  parent="android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/white</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
 

 

Android:dialog去除边框的实现(自带Style的padding)