BottomSheetBehavior_Layout_behavior_hideable 如何转换为 app:behavior_hideable?
How does BottomSheetBehavior_Layout_behavior_hideable get translated to app:behavior_hideable?
在 BottomSheetBehavior 的 Android 文档中说我可以在 XML 中使用以下属性:
BottomSheetBehavior_Layout_behavior_hideable
我试过这个:
android:BottomSheetBehavior_Layout_behavior_hideable="true"
但这给了我以下错误:
Unknown attribute android:BottomSheetBehavior_Layout_behavior_hideable
Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding 讨论了该错误,但 none 这些解决方案对我有用,因为它们是关于同步项目文件的。我的是同步的。没有人质疑属性名称的有效性,我认为这是我的问题。
然后我试了这个:
app:BottomSheetBehavior_Layout_behavior_hideable="true"
但这给了我以下错误:
Unexpected namespace prefix "app" found for tag
该错误在 Unexpected namespace prefix "app" found for tag RelativeLayout - Android? 中进行了讨论,但是 none 这些解决方案对我有用,并且 - 对我的问题更重要 - 属性似乎是这样写的:
app:behavior_hideable="true"
app:behavior_hideable
是BottomSheetBehavior_Layout_behavior_hideable
的正确写法吗?执行此翻译的机制的名称是什么?它的文档在哪里?
答案有几个组成部分。
- 在
BottomSheetBehavior
的构造函数中,xml属性被读出如下Source:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
- 这些属性通常在
attrs.xml file
中定义。这是 BottomSheetBehavior 的 attrs.xml。
所以这里发生的是 LayoutInflater
调用构造函数,并且 xml 属性通过 R.styleable.[name_of_style]_[name_of_attribute]
访问。当你想应用 xml 中的样式时,你只需使用属性的名称。本例中,样式名称为"BottomSheetBehavior_Layout",属性名称为"behavior_hideable"。同样,您也可以使用 "behavior_skipCollapsed" 和 "behavior_fitToContents".
关于样式的更多信息,官方文档在这里:https://developer.android.com/training/custom-views/create-view#customattr
在 BottomSheetBehavior 的 Android 文档中说我可以在 XML 中使用以下属性:
BottomSheetBehavior_Layout_behavior_hideable
我试过这个:
android:BottomSheetBehavior_Layout_behavior_hideable="true"
但这给了我以下错误:
Unknown attribute android:BottomSheetBehavior_Layout_behavior_hideable
Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding 讨论了该错误,但 none 这些解决方案对我有用,因为它们是关于同步项目文件的。我的是同步的。没有人质疑属性名称的有效性,我认为这是我的问题。
然后我试了这个:
app:BottomSheetBehavior_Layout_behavior_hideable="true"
但这给了我以下错误:
Unexpected namespace prefix "app" found for tag
该错误在 Unexpected namespace prefix "app" found for tag RelativeLayout - Android? 中进行了讨论,但是 none 这些解决方案对我有用,并且 - 对我的问题更重要 - 属性似乎是这样写的:
app:behavior_hideable="true"
app:behavior_hideable
是BottomSheetBehavior_Layout_behavior_hideable
的正确写法吗?执行此翻译的机制的名称是什么?它的文档在哪里?
答案有几个组成部分。
- 在
BottomSheetBehavior
的构造函数中,xml属性被读出如下Source:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
- 这些属性通常在
attrs.xml file
中定义。这是 BottomSheetBehavior 的 attrs.xml。
所以这里发生的是 LayoutInflater
调用构造函数,并且 xml 属性通过 R.styleable.[name_of_style]_[name_of_attribute]
访问。当你想应用 xml 中的样式时,你只需使用属性的名称。本例中,样式名称为"BottomSheetBehavior_Layout",属性名称为"behavior_hideable"。同样,您也可以使用 "behavior_skipCollapsed" 和 "behavior_fitToContents".
关于样式的更多信息,官方文档在这里:https://developer.android.com/training/custom-views/create-view#customattr