【发布时间】:2018-03-04 01:13:45
【问题描述】:
我在互联网上找到了这段代码,但我的回收站不会通过这段代码改变属性。有什么解决办法吗?
在 XML 中做对了,但在编程上什么都没有。
<com.ScrollRecyclerView
style="@style/scrollbar_shape_style"
android:id="@+id/drop_down_list"
android:layout_width="wrap_content"
android:layout_height="300dp"></com.ScrollRecyclerView>
public class ScrollRecyclerView extends RecyclerView {
public ScrollRecyclerView(Context context) {
super(context);
}
public ScrollRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs, R.attr.scrollbarStyle);
}
public ScrollRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, R.attr.scrollbarStyle);
}
}
【问题讨论】:
-
这是一个带有标准构造函数的简单 Recyclerview 子类。它不做任何默认 Recyclerview 不做的事情。
-
你是如何使用子类的,直接通过 XML,还是创建自己的 AttributeSet 并通过构造函数实例化自己?
-
我通过 ID 从 XML 使用
-
R.attr.scrollbarStyle 不是样式。这是一个可以通过样式更改的属性。
-
R.attr.scrollbarStyle 和 R.style.scrollbar_shape_style 的结果相同
标签: android android-recyclerview styles attr