android圆角框–透明背景圆角框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#CCFFFFFF" />
<stroke
android:width="3dp"
android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
</shape>
dialog 圆角框—解决dialog边角显示不透明问题
自定义dialog style
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.6</item>
</style>
自定义dialog
public class MyDialog extends Dialog{
public MyDialog(Context context) {
super(context);
}
public MyDialog(Context context, View view, int style) {
this(context, view.getWidth(), view.getHeight(), view, style);
}
public MyDialog(Context context, int width, int height, View layout, int style) {
super(context, style);
setContentView(layout);
Window window = getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.CENTER;
window.setAttributes(params);
}
}
自定义dialog示例
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_img_dangda, null);
ImageButton ib_close = (ImageButton) view
.findViewById(R.id.ib_dialog_fangda_close);
ImageView iv_img_big = (ImageView) view
.findViewById(R.id.iv_img_fangda);
Bitmap bitmap = ThumbnailUtils.extractThumbnail(
getDrawableBitmap(currentMovie.getResource()), 640, 810);
iv_img_big.setImageBitmap(bitmap);
ib_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog = new MyDialog(this, view, R.style.dialog);
dialog.show();
效果