Android: EditText multi-line text inside BottomSheetDialog

I have a bottom sheet dialog and there is an EditText in the layout. EditText - multi-line, maximum - 3. I put:

commentET.setMovementMethod(new ScrollingMovementMethod());
commentET.setScroller(new Scroller(bottomSheetBlock.getContext()));
commentET.setVerticalScrollBarEnabled(true);

but when the user starts to scroll the EditText text vertically, the BottomSheetBehavior and EditText capture events will not scroll vertically.

enter image description here

Does anyone know how to solve this problem?

+4
source share
2 answers

Here is an easy way to do this.

yourEditTextInsideBottomSheet.setOnTouchListener(new OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
        v.getParent().requestDisallowInterceptTouchEvent(true);
        switch (event.getAction() & MotionEvent.ACTION_MASK){
        case MotionEvent.ACTION_UP:
            v.getParent().requestDisallowInterceptTouchEvent(false);
            break;
        }
        return false;
   }
});
+4
source

I solve these problems as follows:

  • I created a custom work around the behavior of the bottom sheet, expanding my own android BottomSheetBehavior:

    public class WABottomSheetBehavior<V extends View> extends BottomSheetBehavior<V> {
    private boolean mAllowUserDragging = true;
    
    public WABottomSheetBehavior() {
        super();
    }
    
    public WABottomSheetBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public void setAllowUserDragging(boolean allowUserDragging) {
        mAllowUserDragging = allowUserDragging;
    }
    
    @Override
    public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
        if (!mAllowUserDragging) {
            return false;
        }
        return super.onInterceptTouchEvent(parent, child, event);
    }
    }
    
  • EditText, EditText, setAllowUserDragging:

    commentET.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (v.getId() == R.id.commentET) {
            botSheetBehavior.setAllowUserDragging(false);
            return false;
        }
        return true;
    }
    });
    
+1

Source: https://habr.com/ru/post/1658688/


All Articles