How to set the attribute "android:scrollbars" programmatically for a view in Xamarin Android C#?

216 Views Asked by At

I am using NestedScrollView control in my Xamarin Android application as recommended in Android forums. In which the scrollbars are not visible, but the scrolling is working. I want to enable to enable the scrollbars and tried the scrollbar related APIs in the NestedScrollView and found it was not working. While searching I found this link, where it says to set the "android:scrollbars" attribute in XML file to enable it. I would like to set this programmatically in C# but I am unable to find any relevant code for this. Anyone please advice me how to achieve this?

1

There are 1 best solutions below

3
On

This is a known issue which I reported here : https://github.com/xamarin/Xamarin.Forms/issues/7629.

This issue has not been fixed yet .

The only workaround is to enable the scrollbar in xml(based on my test).

Xml

 <androidx.core.widget.NestedScrollView    
          android:id="@+id/nsvMain"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:scrollbars="vertical"
        >

Code behind

var view = FindViewById<NestedScrollView>(Resource.Id.nsvMain);
view.VerticalScrollBarEnabled = true; //not work