Is it possible to disable specific XML attributes from a custom view in Android?
-
24-05-2021 - |
Question
I'm creating my own personalized ListView by extending the ListView
itself. This particular ListView shouldn't have scrollbars.
- How can I disable the XML
android:scrollbars
attribute for my customListView
? - I can't find a way to disable them programmatically. What am I missing?
The answer from dzeikei's will disable the scrollbars programmatically and ignore any value from android:scrollbars
but what I'm really asking on 1. is how to make android:scrollbars
an invalid attribute for my custom component.
Solution
Updated OK as Richardo found out, seems like my original answer is the reverse way since the scrollbar is displayed internally :)
The correct way will be to call
super.setHorizontalScrollBarEnabled(false)
and super.setVerticalScrollBarEnabled(false)
in the constructor and override setHorizontalScrollBarEnabled()
and setVerticalScrollBarEnabled()
do nothing :D
Override
isHorizontalScrollBarEnabled()
andisVerticalScrollBarEnabled()
in your subclass to returnfalse
.you could also override
setHorizontalScrollBarEnabled()
andsetVerticalScrollBarEnabled()
for good measure.
OTHER TIPS
Try keeping @null for android:scrollbars. Am not sure. But, I usually use @null when i want to remove anything from XML attributes.