开发者

Android how to set ScrollBar in Edittext?

I want to ScrollText in Edittext and also show Scrollbar at corner. I Scroll the text开发者_运维技巧 By Using

questionEntry.setScroller(new Scroller(myContext)); 
questionEntry.setMaxLines(1); 
questionEntry.setVerticalScrollBarEnabled(true); 
questionEntry.setMovementMethod(new ScrollingMovementMethod()); 

Scrolling text works, but the ScrollBar isn't visible. How can I make it visible?


This may help you.

<EditText android:id="@+id/edt_task_disc" android:layout_width="wrap_content"
                      android:layout_height="wrap_content"  android:gravity="top"
                      android:background="@drawable/text_aerea" 
                      android:hint="Task Discription"
                      android:textSize="15sp" android:paddingLeft="5dp"
                      android:maxHeight="35dp"
                      android:scrollbars="vertical"
                      />

Please add android:scrollbars="vertical" to your xml code of edit text, and it will work fine.


Only sample

In Your Java file

 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;
                }
            });

And in your Xml file ...

<EditText
        android:id="@+id/DwEdit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="9"
        android:ems="10"
        android:gravity="top"
        android:imeOptions="flagNoExtractUi"

        android:minLines="10"
        android:scrollHorizontally="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:scrollbarStyle="insideInset"
        android:scrollbars="vertical" 
        android:overScrollMode="always"
        android:inputType="textCapSentences">
        </EditText>


I have checked too options but i think

 android:scrollbars="vertical"

this is best or you can do it by defining multiline

android:inputType="textMultiLine"

or also you can solve this issue by

edittext.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            view.getParent().requestDisallowInterceptTouchEvent(true);
            switch (motionEvent.getAction() & MotionEvent.ACTION_MASK){
                case MotionEvent.ACTION_UP:
                    view.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
            }

            return false;
       }

  });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜