wasabeef / richeditor-android

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.
Apache License 2.0
6.25k stars 1.2k forks source link

when richeditor in scrollview , the cursor will be below of keyboard #71

Open oldfeel opened 8 years ago

oldfeel commented 8 years ago

text is: cursor at here

9032b3ab0c4b45f518024d6b29201ad3

SmiffyKMc commented 8 years ago

I was having the same issue and added android:windowSoftInputMode="adjustResize" in my tag. Now the cursor will always stay above the keyboard and you can scroll etc fine.

guobinAndroid commented 7 years ago

I also encountered this problem, I would like to ask how to solve the problem,added android:windowSoftInputMode="adjustResize" is no use

JasonLinkinBright commented 7 years ago

The same problem! Cursor is behind the softkeyboard.

danieltigse commented 6 years ago

android:windowSoftInputMode="adjustResize" doesn't work for me. Any other idea?

ejwdhr commented 6 years ago

Did you guys solved?

ashish-bahl commented 6 years ago

I used this: `editor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {

        @Override
        public void onTextChange(String text) {
            if (!text.isEmpty()) {
                mScroll.post(new Runnable() {
                    @Override
                    public void run() {
                        mScroll.fullScroll(View.FOCUS_DOWN);
                    }
                });
            } else {
                mScroll.post(new Runnable() {
                    @Override
                    public void run() {
                        mScroll.fullScroll(View.FOCUS_UP);
                    }
                });
            }
        }
    });`

where editor is Rich Editor and mScroll is the ScrollView

dhruvkaushal11 commented 6 years ago

Thanks, @abahl817 But still it ruins everything when you try to edit in between text

The best thing I come up with was to remove the Editor from Scrollview

beczesz commented 6 years ago

I would need solution too to this one

dhruvkaushal11 commented 6 years ago

@beczesz Don't put web view inside the scroll view.

HaidyCao commented 5 years ago

I found a solution:

        mRichEditor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {

        int oldScrollViewHeight = 0;
        int oldScrollY = 0;

        @Override
        public void onTextChange(String text) {
            if (text.isEmpty()) {
                return;
            }

            int scrollViewHeight = mScrollView.getChildAt(0).getHeight();
            int scrollY = mScrollView.getScrollY();

            if (oldScrollViewHeight != scrollViewHeight) {
                if (oldScrollViewHeight == 0) {
                    mScrollView.fullScroll(View.FOCUS_DOWN);
                } else {
                    int offset = scrollViewHeight - oldScrollViewHeight;
                    if (offset > 0) {
                        mScrollView.scrollBy(0, offset);
                    }
                }
            }

            oldScrollY = scrollY;
            oldScrollViewHeight = scrollViewHeight;
        }
    });
rubendarioramirez commented 5 years ago

None of the solutions worked for me.

rubendarioramirez commented 5 years ago

Thanks, @abahl817 But still it ruins everything when you try to edit in between text

The best thing I come up with was to remove the Editor from Scrollview

But how do you scroll the text later?

Nivas78 commented 5 years ago

For me also getting same issue,After 15 lines Cursor is going Below keypad .

Any solution for this ,Any Idea..

rubendarioramirez commented 5 years ago

For me also getting same issue,After 15 lines Cursor is going Below keypad .

Any solution for this ,Any Idea..

I just found the solution. Just remove the scroll view, keep just the editor inside a constraint view, like this:

<jp.wasabeef.richeditor.RichEditor
    android:id="@+id/editor"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    android:background="?android:attr/colorBackground"
    app:layout_constraintBottom_toTopOf="@+id/adView_offile_story"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/editorView"
    app:layout_constraintVertical_bias="0.0" />

Then go to your activity and add this line: getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

That will do the work. I realized that the rich text editor it's already scrolling by adding another scrollview, it creates a conflict. I hope it works for you, it did for me.

Also if you want to have even more space, you can add more PADDING bottom when you initialize the editor, a value of 50 gives enough space to have always the cursor around middle of the screen.

Nivas78 commented 5 years ago

For me also getting same issue,After 15 lines Cursor is going Below keypad . Any solution for this ,Any Idea..

I just found the solution. Just remove the scroll view, keep just the editor inside a constraint view, like this:

<jp.wasabeef.richeditor.RichEditor
    android:id="@+id/editor"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginBottom="8dp"
    android:background="?android:attr/colorBackground"
    app:layout_constraintBottom_toTopOf="@+id/adView_offile_story"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/editorView"
    app:layout_constraintVertical_bias="0.0" />

Then go to your activity and add this line: getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

That will do the work. I realized that the rich text editor it's already scrolling by adding another scrollview, it creates a conflict. I hope it works for you, it did for me.

Also if you want to have even more space, you can add more PADDING bottom when you initialize the editor, a value of 50 gives enough space to have always the cursor around middle of the screen.

No luck,Still Same issue

ashish-bahl commented 5 years ago

Thanks, @abahl817 But still it ruins everything when you try to edit in between text The best thing I come up with was to remove the Editor from Scrollview

But how do you scroll the text later?

@rubendarioramirez I just leave the rest to the user ;p

jasonSuzhow commented 5 years ago

`/**

test this SoftHideKeyBoardUtil.assistActivity(this) , it's ok for me

ChanphengHor commented 5 years ago

ViewTreeObserver observer = scrollView.getViewTreeObserver(); observer.addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener(){ @Override public void onScrollChanged() { scrollX = scrollView.getScrollX(); scrollY = scrollView.getScrollY(); } }); //=======================================================/ mRichEditor.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if(mEditor.getHtml() != null && !mEditor.getHtml().isEmpty()){ scrollView.scrollTo(0,scrollY + getDP(18)); } } });

birdfly2014 commented 5 years ago

Has anybody solved it?

rubendarioramirez commented 5 years ago

Has anybody solved it?

Yes, with this: getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

wenge8n commented 5 years ago

This one works without scrollview. But not working inside scrollview. Anybody solved this issue inside scrollview? I need to use webview inside scrollview.

yyyalmanci commented 4 years ago

class customEditor : RichEditor {

private lateinit var parentScrollView: NestedScrollView
private var scrollSize = 0

constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
    context,
    attrs,
    defStyleAttr
)

override fun onAttachedToWindow() {
    super.onAttachedToWindow()
    onChangeListener()
}

private fun onChangeListener() {
    this.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
        scrollSize = oldScrollY
        parentScrollView.onNestedScroll(parentScrollView, 0, 0, 0, scrollSize)
        //this for last line of editorr
    }
    parentScrollView.onLayoutChange { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
        parentScrollView.onNestedScroll(parentScrollView, 0, 0, 0, scrollSize)
        //this for different line at the editor
    }
}

fun setParentScrollView(parentScroll: NestedScrollView) {
    parentScrollView = parentScroll
}

}

this works fine guys you can try

LongLongLongLongLongLongLongLongLong commented 4 years ago

getDP

请问 getDP(18)是什么意思,是计算RicheEditor中内容的高度吗?

LongLongLongLongLongLongLongLongLong commented 4 years ago

`/**

  • 让输入框在 软键盘上方 */ public class SoftHideKeyBoardUtil { public static void assistActivity(Activity activity) { new SoftHideKeyBoardUtil(activity); } private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; //为适应华为小米等手机键盘上方出现黑条或不适配 private int contentHeight;//获取setContentView本来view的高度 private boolean isfirst = true;//只用获取一次 private int statusBarHeight;//状态栏高度 private SoftHideKeyBoardUtil(Activity activity) { //1、找到Activity的最外层布局控件,它其实是一个DecorView,它所用的控件就是FrameLayout FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); //2、获取到setContentView放进去的View mChildOfContent = content.getChildAt(0); //3、给Activity的xml布局设置View树监听,当布局有变化,如键盘弹出或收起时,都会回调此监听 mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { //4、软键盘弹起会使GlobalLayout发生变化 public void onGlobalLayout() { if (isfirst) { contentHeight = mChildOfContent.getHeight();//兼容华为等机型 isfirst = false; } //5、当前布局发生变化时,对Activity的xml布局进行重绘 possiblyResizeChildOfContent(); } }); //6、获取到Activity的xml布局的放置参数 frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } // 获取界面可用高度,如果软键盘弹起后,Activity的xml布局可用高度需要减去键盘高度 private void possiblyResizeChildOfContent() { //1、获取当前界面可用高度,键盘弹起后,当前界面可用布局会减少键盘的高度 int usableHeightNow = computeUsableHeight(); //2、如果当前可用高度和原始值不一样 if (usableHeightNow != usableHeightPrevious) { //3、获取Activity中xml中布局在当前界面显示的高度 int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); //4、Activity中xml布局的高度-当前可用高度 int heightDifference = usableHeightSansKeyboard - usableHeightNow; //5、高度差大于屏幕1/4时,说明键盘弹出 if (heightDifference > (usableHeightSansKeyboard / 4)) { // 6、键盘弹出了,Activity的xml布局高度应当减去键盘高度 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight; } else { frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } } else { frameLayoutParams.height = contentHeight; } //7、 重绘Activity的xml布局 mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); // 全屏模式下:直接返回r.bottom,r.top其实是状态栏的高度 return (r.bottom - r.top); } }`

test this SoftHideKeyBoardUtil.assistActivity(this) , it's ok for me

对我有用,非常感谢,大佬。