sendtion / XRichText

一个Android富文本类库,支持图文混排,支持编辑和预览,支持插入和删除图片。
1.76k stars 263 forks source link

为什么我是用RichTextEditor插入相册选择的图片,显示是一张灰白的默认图片?而不是我的相册图片呢? #72

Closed roybill closed 4 years ago

roybill commented 4 years ago

1.布局代码: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto">

<Button
    android:id="@+id/btn_select"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_width="match_parent"
    android:text="插入图片"
    android:layout_height="wrap_content"/>

<com.sendtion.xrichtext.RichTextEditor
    android:id="@+id/et_new_content"
    android:layout_width="match_parent"
    android:padding="10dp"
    android:layout_height="0dp"
    app:layout_constraintTop_toBottomOf="@id/btn_select"
    app:layout_constraintBottom_toBottomOf="parent"
    app:rt_editor_text_line_space="6dp"
    app:rt_editor_image_height="500"
    app:rt_editor_image_bottom="10"
    app:rt_editor_text_init_hint="在这里输入内容"
    app:rt_editor_text_size="16sp"
    app:rt_editor_text_color="#55000000"/>

</androidx.constraintlayout.widget.ConstraintLayout>

2.类代码: button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(LingwuyiwuTwo.this, "插入图片", Toast.LENGTH_SHORT).show(); PictureSelector.create(LingwuyiwuTwo.this).openGallery(PictureMimeType.ofImage()) .loadImageEngine(GlideEngine.createGlideEngine()) .forResult(new OnResultCallbackListener() { @Override public void onResult(List result) { // 结果回调 for (LocalMedia media: result) { String path = media.getPath(); LogUtils.d("1619 "+path); // richEditText.insertImage(path); richEditText.insertImage(path);

                            }
                        }
                        @Override
                        public void onCancel() {
                            // 取消
                        }
                    });
        }
    });