在BottomSheetBehavior的Android文档中,它说我可以在XML中使用以下属性:
BottomSheetBehavior_Layout_behavior_hideable我试过这个:
android:BottomSheetBehavior_Layout_behavior_hideable="true"但这给了我以下错误:
未知属性android:BottomSheetBehavior_Layout_behavior_hideable
这个错误在重力,填充物上讨论过,但是没有一个解决方案对我有效,因为它们都是关于同步项目文件的。我的是同步的。没有人质疑属性名的有效性,我认为这就是我的问题所在。
然后我试了一下:
app:BottomSheetBehavior_Layout_behavior_hideable="true"但这给了我以下错误:
为标记找到意外名称空间前缀"app“
这个错误在为标签RelativeLayout - Android找到了意想不到的名称空间前缀"app“?上讨论过,但是这些解决方案对我都没有用,而且--更重要的是我的问题--在这里,属性似乎是这样写的:
app:behavior_hideable="true"app:behavior_hideable是编写BottomSheetBehavior_Layout_behavior_hideable的正确方法吗?执行此转换的机制的名称是什么?它的文件在哪里?
发布于 2018-10-30 17:36:55
答案有几个组成部分。
BottomSheetBehavior的构造函数中,来源属性如下所示TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout); setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
attrs.xml file中定义的。这是BottomSheetBehavior的BottomSheetBehavior。所以这里发生的是一个LayoutInflater调用构造函数,并且通过R.styleable.[name_of_style]_[name_of_attribute]访问xml属性。当您想要在xml中应用样式时,只需使用属性的名称。在这种情况下,样式的名称是"BottomSheetBehavior_Layout",而属性的名称是"behavior_hideable“。同样,您也可以使用"behavior_skipCollapsed“和"behavior_fitToContents”。
有关样式的更多信息,官方文档如下:https://developer.android.com/training/custom-views/create-view#customattr
https://stackoverflow.com/questions/53069440
复制相似问题