网上一些自定义的dialog许多有不能左右对齐等等问题
1定义一个空的dialog
-
public class BaseDialog extends Dialog {
-
-
public BaseDialog(Context context) {
-
super(context, R.style.BaseDialog);
-
}
-
-
@Override
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setCanceledOnTouchOutside(true);
-
Window dialogWindow = getWindow();
-
dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
-
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
-
lp.x = 0;
-
lp.y = 0;
-
dialogWindow.setAttributes(lp);
-
dialogWindow.setLayout(LayoutParams.MATCH_PARENT,
-
LayoutParams.WRAP_CONTENT);
-
dialogWindow.setGravity(Gravity.CENTER);
-
}
-
}
-
<style name="BaseDialog" parent="@android:Theme.Dialog">
-
<item name="android:windowFrame">@null</item>
-
<item name="android:windowNoTitle">true</item>
-
<item name="android:windowContentOverlay">@null</item>
-
<item name="android:windowBackground">@drawable/bg_dialog_null</item>
-
</style>
bg_dialog_null
-
<?xml version="1.0" encoding="utf-8"?>
-
<shape xmlns:android="" >
-
-
<solid android:color="#00000000" />
-
-
</shape>
窗口背景设置成纯透明
2 使用时就可以加载自己的layout了
-
final BaseDialog dialog = new BaseDialog(BaseActivity.this);
-
dialog.setContentView(R.layout.dialog_update_unwanted);
-
dialog.findViewById(R.id.dialog_update_unwanted_tv_confirm).setOnClickListener(new OnClickListener() {
-
-
@Override
-
public void onClick(View v) {
-
dialog.dismiss();
-
}
-
});
-
TextView tv = (TextView) dialog.findViewById(R.id.dialog_update_unwanted_tv_info);
-
tv.setText(sb);
-
dialog.show();
补充,要用Dialog的话
-
dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
可以解决不能拉伸到边的问题
阅读(387) | 评论(0) | 转发(0) |