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

Viewed 5719

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?

4 Answers
    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);

Programmatically :

RecyclerView mRecyclerView =rootView.findViewById(R.id.your-recycler-view);
if(mRecyclerView!=null){
  mRecyclerView.setVerticalScrollBarEnabled( true );
}

In the XML :

<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="vertical"
android:layout_height="wrap_content" />

Other scrollbars:

android:scrollbars="vertical"
android:scrollbars="horizontal"
android:scrollbars="vertical|horizontal"
Related