Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set "android:scrollbars=vertical" programmatically?

Tags:

android

I want to dynamically set scrollbars in an EditText programmatically, but I don't find this api as setscrollbars. Could anyone tell me if this can be done programmatically?

android:scrollbars="vertical"

Is this possible? How can I achieve this programmatically?

like image 291
pengwang Avatar asked Aug 28 '10 07:08

pengwang


2 Answers

I was looking for a method to do this programatically, too.

Seems from http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars it's not possible, cause no related method is mentioned there.

The only method that sounds good by description is:

View.setVerticalScrollBarEnabled(boolean)

but in my case it didn't work. But that may depend on the layout and the way it is used.

I am thinking now about having two layouts: one with the attribute set to "none" and one set to "vertical". Then in code I could decide which to use.

like image 171
sunadorer Avatar answered Sep 29 '22 03:09

sunadorer


    final TypedArray typedArray = context.obtainStyledAttributes(null,  new int[]{});
            try {
                Method method = View.class.getDeclaredMethod("initializeScrollbars" , TypedArray.class);
                method.invoke(this, typedArray);
            }catch (Exception e) {
            }
            typedArray.recycle();
 setVerticalScrollBarEnabled(true);
like image 40
Jacky.Lee Avatar answered Sep 29 '22 02:09

Jacky.Lee