我正在使用Custom AlertDialog.Builder将SD卡中的图像显示到该警报对话框中。
如何使用Screen的全宽和高度来显示对话框,这是我的代码:
viewHolder.imageButtonView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final AlertDialog.Builder imageDialog = new AlertDialog.Builder(XRayActivity.this);
final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.image_dialog, null);
ImageView image = (ImageView) layout.findViewById(R.id.imageView);
try
{
strFileName = arrayList.get(position).getFilename().toString();
String file = Environment.getExternalStorageDirectory().getPath() + "/Pictures/XRays/" + strFileName;
Bitmap bm = BitmapFactory.decodeFile(file);
image.setScaleType(ImageView.ScaleType.FIT_XY);
image.setImageBitmap(bm);
} catch (Exception e) {
e.printStackTrace();
}
imageDialog.setTitle(strFileName);
imageDialog.setView(layout);
imageDialog.setPositiveButton(android.R.string.ok, new
DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
imageDialog.create();
imageDialog.show();
}
});
image_dialog.xml: -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
在xml中,我只使用具有layout_width和layout_height的match_parent属性的ImageView。
答案 0 :(得分:2)
您可以使用Dialog Fragment:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
}
答案 1 :(得分:0)
您可以使用样式来执行此操作
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}