2

I have a dialog fragment, in which I have a recycler view. I want to add a scrollbar to the recycler view. I added scrollbars="vertical" but it's not showing up. I think the issue has something to do with the themes. Here is my xml:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="16dp"
tools:context="com.airxos.app.common.fragments.LayerSwitcherFragment">

<TextView
    android:id="@+id/layer_list_title"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:fontFamily="sans-serif"
    android:textSize="20sp"
    android:textStyle="bold"
    android:textColor="@color/black_87"
    android:text="@string/layers"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/layer_list"
    android:layout_marginTop="@dimen/margin_16"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/layer_list_title"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_height="0dp"
    android:maxHeight="@dimen/info_window_height"
    android:layout_width="match_parent"
    android:nestedScrollingEnabled="true"
    android:scrollbars="vertical"
    android:background="@color/white"
    android:scrollbarThumbVertical="@drawable/scrollbar"
    android:scrollbarSize="5dp"
    android:padding="5dp"
    android:scrollbarStyle="insideInset"/>
</android.support.constraint.ConstraintLayout>

I am restricting the height and width of the dialog fragment as shown below:

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    Objects.requireNonNull(inflater, "LayoutInflater");

    if(getDialog().getWindow() != null) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        getDialog().setCanceledOnTouchOutside(true);
    }
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_layer_switcher, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Objects.requireNonNull(view, "View");

    super.onViewCreated(view, savedInstanceState);
    layerList = view.findViewById(R.id.layer_list);
    layerList.setAdapter(new LayerListAdapter(context, layers, layerSelectionListener));
    layerList.setLayoutManager(new LinearLayoutManager(context));
}

I have already tried everything suggested in this SO question and it did not work.

Other than this I have also tried creating a drawable and adding it as scrollbarThumbVertical

I think it has something to do with the themes because even when I change the background color of constraint layout it is not showing up in the dialog.

EDIT: I am showing the dialog as shown below:

LayerSwitcherFragment switcherFragment = LayerSwitcherFragment.newInstance(layers);
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
Fragment prev = getChildFragmentManager().findFragmentByTag("layer_dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
switcherFragment.show(ft, "layer_dialog");

EDIT: Issue is solved. I am sorry for wasting everyone's time. The issue was a stupid mistake we made. My DialogFragment was in a Library. We build the arr file and was using it inside the app. The issue was that we forgot to remove the dialogfragment's XML files from the main app when we refactored it to the arr library. So even after we update the files in the library, the app was picking up the old file in the main app instead of the updated file because the name of the XML was the same.

hushed_voice
  • 3,161
  • 3
  • 34
  • 66

5 Answers5

1

Try:

android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
1

Try This:

In XML:

  <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:scrollbars="vertical" <!-- type of scrollbar -->
        android:scrollbarThumbVertical="@android:color/darker_gray"  
        android:scrollbarSize="5dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
  • Hi, thanks for the response. But please check out my code in my question. I have all the attributes you mentioned. (except having android:scrollbars="vertical" twice) But it still doesn't work – hushed_voice Aug 12 '19 at 06:44
1

In your xml, Just set the android:scrollbars="vertical" it can work.

<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
Longalei
  • 453
  • 3
  • 8
0

I know this can come kind of late. Try to use a NestedScrollView as the parent of the RecyclerView. Like this:

<androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/layer_list_title"
            app:layout_constraintEnd_toEndOf="parent"
            android:scrollbars="vertical">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/layer_list"
        android:layout_marginTop="@dimen/margin_16"
        android:layout_height="wrap_content"
        android:maxHeight="@dimen/info_window_height"
        android:layout_width="match_parent"
        android:nestedScrollingEnabled="true"
        android:background="@color/white"
        android:padding="5dp"/>
        
</androidx.core.widget.NestedScrollView>
Raimundo
  • 605
  • 7
  • 21
0

I guess in DialogFragment you scrollbar is transparent

try this code

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/mTaskListRV"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbarSize="5dp"
    android:scrollbarThumbVertical="@drawable/shape_progress"
    android:scrollbarTrackVertical="@drawable/shape_round_gray"
    android:scrollbars="vertical"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    tools:listitem="@layout/cash_out_task_list_item_layout" />
qinwei
  • 1