【问题标题】:Custom recyclerview won't to change attribute自定义recyclerview不会改变属性
【发布时间】: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


【解决方案1】:

R.attr.scrollbarStyle 不是样式。这是一个可以通过样式更改的属性。

如果您希望 RecyclerView 显示滚动条,请设置 XML 中的 android:scrollbars 属性。

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

【讨论】:

    【解决方案2】:

    我想通过这个属性自定义滚动条

    <style name="AppTheme" parent="@style/Theme.Leanback">
        <item name="@attr/scrollbarStyle">@style/scrollbar_shape_style</item>
    </style>
    
    <attr name="scrollbarStyle" format="reference"/>
    
    <style name="scrollbar_shape_style">
        <item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
        <item name="android:scrollbarStyle">outsideOverlay</item>
        <item name="android:scrollbars">vertical</item>
        <item name="android:fadeScrollbars">false</item>
        <item name="android:scrollbarThumbVertical">@drawable/scrollbar_vertical_thumb</item>
        <item name="android:scrollbarTrackVertical">@drawable/scrollbar_vertical_track</item>
        <item name="android:scrollbarSize">8dp</item>
    </style>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-21
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多