代码之家  ›  专栏  ›  技术社区  ›  Michael Osofsky

如何将BottomSheetBehavior\u Layout\u behavior\u Hiddeable转换为app:behavior_hideable?

  •  2
  • Michael Osofsky  · 技术社区  · 7 年前

    在Android文档中 BottomSheetBehavior

    BottomSheetBehavior_Layout_behavior_hideable
    

    我试过这个:

    android:BottomSheetBehavior_Layout_behavior_hideable="true"
    

    但这给了我以下错误:

    未知属性android:BottomSheetBehavior_Layout_behavior_hideable

    Unknown attribute android:layout_width, layout_height, id, gravity, layout_gravity, padding

    然后我尝试了这个:

    app:BottomSheetBehavior_Layout_behavior_hideable="true"
    

    但这给了我以下错误:

    为标记找到意外的命名空间前缀“app”

    这个错误将在 Unexpected namespace prefix "app" found for tag RelativeLayout - Android?

    app:behavior_hideable="true"
    

    app:behavior_hideable 正确的写作方法 BottomSheetBehavior_Layout_behavior_hideable ? 执行此转换的机制的名称是什么?文件在哪里?

    1 回复  |  直到 7 年前
        1
  •  3
  •   chessdork    7 年前

    答案有几个组成部分。

    1. BottomSheetBehavior ,xml属性读取如下 Source :

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout); setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));

    1. attrs.xml file attrs.xml 因为你的行为。

    所以这里发生的是 LayoutInflater R.styleable.[name_of_style]_[name_of_attribute] . 当您想在xml中应用样式时,只需使用属性的名称。在这种情况下,样式的名称是“BottomSheetBehavior\u Layout”,属性的名称是“behavior\u hiddeable”。同样,您也可以使用“behavior\u skipCollapsed”和“behavior\u fitToContents”。

    有关样式的更多信息,请参见以下官方文档: https://developer.android.com/training/custom-views/create-view#customattr