dialog全屏显示图片

来源:互联网 发布:虚拟机装mac蓝屏 编辑:程序博客网 时间:2024/06/05 19:19
主题<style name="quick_option_dialog" parent="@style/Theme.AppCompat.Dialog">    <item name="android:windowBackground">@color/white</item></style>public class CustomDialog extends Dialog {    public CustomDialog(Context context,String path) {        //重写dialog默认的主题        this(context, R.style.quick_option_dialog,path);    }    public CustomDialog(Context context, int themeResId,String path) {        super(context, themeResId);        View convertView = getLayoutInflater().inflate(R.layout.dialog_photo_entry, null);        requestWindowFeature(Window.FEATURE_NO_TITLE);        ImageView img = (ImageView) convertView.findViewById(R.id.large_image);        img.setImageDrawable(stringToDrawable(path));        convertView.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {               dismiss();            }        });        setContentView(convertView);    }    @Override    protected void onCreate(Bundle bundle) {        super.onCreate(bundle);        getWindow().setGravity(Gravity.BOTTOM); //显示在底部        WindowManager m = getWindow().getWindowManager();        Display d = m.getDefaultDisplay();        WindowManager.LayoutParams p = getWindow().getAttributes();        p.width = d.getWidth(); //设置dialog的宽度为当前手机屏幕的宽度        getWindow().setAttributes(p);    }    /**     * 本地图片转为drawable方法     *     * @param path     * @return     */    public static Drawable stringToDrawable(String path) {        FileInputStream input = null;        try {            input = new FileInputStream(new File(path));        } catch (FileNotFoundException e) {            e.printStackTrace();        }        // 先转换成bitmap        Bitmap bmp = BitmapFactory.decodeStream(input);        // 再转换成drawable        @SuppressWarnings("deprecation")        Drawable drawable = new BitmapDrawable(bmp);        return drawable;    }}

0 0