In the Android documentation for BottomSheetBehavior, it says I can use the following attribute in XML:
BottomSheetBehavior_Layout_behavior_hideable
I tried this:
android:BottomSheetBehavior_Layout_behavior_hideable="true"
But that gave me the following error:
Unknown attribute android:BottomSheetBehavior_Layout_behavior_hideable
That error is discussed at Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding but none of those solutions worked for me because they were about syncing project files. Mine are synced. Nobody questioned the validity of the attribute name, which is what I think is my problem here.
Then I tried this:
app:BottomSheetBehavior_Layout_behavior_hideable="true"
But that gave me the following error:
Unexpected namespace prefix "app" found for tag
That error is discussed at Unexpected namespace prefix "app" found for tag RelativeLayout - Android? but none of those solutions worked for me, and--more central to my question--there the attribute seems to be written like this:
app:behavior_hideable="true"
Is app:behavior_hideable the correct way to write BottomSheetBehavior_Layout_behavior_hideable? What is the name of the mechanism that performs this translation? Where is its documentation?
There are a couple of components to the answer.
BottomSheetBehavior, xml attributes are read out as follows Source:TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
attrs.xml file. Here's the attrs.xml for the BottomSheetBehavior.So what's happening here is a LayoutInflater is calling the constructor, and xml attributes are accessed via R.styleable.[name_of_style]_[name_of_attribute]. When you want to apply the style in xml, you simply use the name of the attribute. In the case, the name of the style is "BottomSheetBehavior_Layout", and the name of the attribute is "behavior_hideable". Similarly, you could also use "behavior_skipCollapsed" and "behavior_fitToContents".
For more information on styling, the official docs are here: https://developer.android.com/training/custom-views/create-view#customattr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With