Enabling scrollbar in Android EditText

I have an EditText on my layout. The following are the attributes that I have:

<EditText android:id="@+id/entryIdea" android:layout_width="fill_parent" android:layout_height="225sp" android:gravity="top" android:background="@android:drawable/editbox_background" android:scrollbars="vertical"/> 

However, I can see the scroll bar, but I can not scroll it with the mouse / touch. I thought this might work if I put the appropriate listener since it works in a TextView. This is apparently not the case.

 EditText et = (EditText)findViewById(R.id.entryIdea); et.setMovementMethod(new ScrollingMovementMethod()); 

Can you guys help me with this?

Thank you so much in advance. Seaya

+6
android android-edittext scrollbar
source share
7 answers

In your XML, try setting the EditText height not to layout_height , but rather use the android:lines attribute (btw, using sp is usually not a good practice when setting the size for anything other than the font size). Using dp / dip in this case is more natural).

Meanwhile set layout_height to wrap_content . Otherwise, the XML you presented (with the changes I mentioned) worked fine for me even without specifying the move method in the code.

And, of course, the scrollbar will appear when the actual number of lines of text in the EditText is greater than that specified in the android: lines attribute.

+7
source share

the link

  EditText dwEdit = (EditText) findViewById(R.id.DwEdit); dwEdit.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub if (view.getId() ==R.id.DwEdit) { view.getParent().requestDisallowInterceptTouchEvent(true); switch (event.getAction()&MotionEvent.ACTION_MASK){ case MotionEvent.ACTION_UP: view.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } }); 
+3
source share
 editText1.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub if (view.getId() ==R.id.editText1) { view.getParent().requestDisallowInterceptTouchEvent(true); switch (event.getAction()&MotionEvent.ACTION_MASK){ case MotionEvent.ACTION_UP: view.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } }); 
+3
source share

use this:

  android:maxLines="5" 

for your xml file. Then the scroll attribute will work.

+2
source share
 editText1.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub if (view.getId() ==R.id.editText1) { view.getParent().requestDisallowInterceptTouchEvent(true); switch (event.getAction()&MotionEvent.ACTION_MASK){ case MotionEvent.ACTION_UP: view.getParent().requestDisallowInterceptTouchEvent(false); break; } } return false; } }); 
+1
source share

Your XML file uses:

 android:maxLines="5" 
0
source share

in xml file:

android: MAXLINES = "5" android: scrollbars = "vertical"

and in the .java file add

edt_text.setMovementMethod (new ScrollingMovementMethod ());

0
source share

All Articles