Fast scroll in an EditText

1.1k views Asked by At

My EditText can have sometimes very large text (>1000 lines) and I want to be able to quickly reach the start or the end so I thought fast scroll was the solution, however it is not available for EditText, nor ScrollView, only for ListView. I found some editing apps that do have the fast scroll bar in their EditText. How did they do it? Setting smoothScrollEnabled on parent ScrollView doesn't work

2

There are 2 answers

6
Charuක On

By quoting this,

You can use a ScrollView and place your EditText inside it and mention the position of it that you need fast/smooth scrolling.

    scrollview = (ScrollView) findViewById(R.id.scroll_view) ;
    scrollview.setSmoothScrollingEnabled ( true );
    scrollview.smoothScrollBy (int dx, int dy); //dx,dy.. offset (Relative Position)
    scrollview.smoothScrollTo (int x, int y); //scroll to x and y (actual position)
0
sandip On
<ScrollView
    android:id="@+id/scrollViewEditText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="60dp"
    android:layout_marginBottom="60dp"
    android:fillViewport="true"
    android:scrollbarThumbHorizontal="@null"
    android:scrollbarThumbVertical="@null"
    android:visibility="visible">

    <EditText
        android:id="@+id/etBook"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="15dp"
        android:background="@null"
        android:fastScrollEnabled="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:fontFamily="@font/futurabook"
        android:gravity="top"
        android:hint="Tap to start writing ...."
        android:importantForAutofill="no"
        android:inputType="textMultiLine"
        android:lineSpacingExtra="0sp"
        android:minHeight="48dp"
        android:textColor="@color/colorSecondaryVariant"
        android:textSize="17sp"
        tools:ignore="SpeakableTextPresentCheck" />

</ScrollView>