0

I want to show scroll when the listview is touched and want to disappear when not touched irrespective of the number of items in a listview.

This is what my current snippet looks like

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ListView
        android:id="@+id/list_profile"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:divider="#40ffffff"
        android:dividerHeight="1dp"
        android:fastScrollEnabled="true"
        android:scrollbarStyle="insideOverlay"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#B1FFFFFF" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="18dp"
        android:paddingLeft="35dp"
        android:paddingRight="35dp"
        android:paddingTop="18dp">

        <com.bleexample2.CustomView.MyEditText
            android:id="@+id/edit_search"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:background="@drawable/bg_edit_text"
            android:hint="성함을 입력해주세요"
            android:lines="1" />

        <ImageButton
            android:id="@+id/btn_search"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:scaleType="centerInside"
            android:src="@drawable/ic_search" />

        <ImageButton
            android:id="@+id/btn_add_profile"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:scaleType="centerInside"
            android:src="@drawable/ic_add" />
    </LinearLayout>
</LinearLayout>

My styles.xml looks like this :

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:textColor">#c6c6c6</item>
        <item name="android:editTextColor">@color/editTextTextColor</item>

        <item name="android:fastScrollTrackDrawable">@drawable/fast_scrollbar_track</item>
        <item name="android:fastScrollThumbDrawable">@drawable/ic_thumb</item>

    </style>

    <style name="AppTheme.CustomFastScrollBar" parent="AppTheme" >
        <item name="android:fastScrollThumbDrawable">@drawable/scroll_bar_vertical_thumb</item>
        <item name="android:fastScrollTrackDrawable">@drawable/scrollbar_vetical</item>
        <item name="android:fadeScrollbars">false</item>
    </style>

Using the fastScrollAlwaysVisible I can only set it to either always show or not show. How can I achieve what I want , which is to only show when listview is touched.

Diwesh Saxena
  • 153
  • 1
  • 3
  • 10
  • Just remove the `fastScrollAlwaysVisible` attribute. The default behavior is to autohide the fast-scroller when you're not touching the `ListView`. – Mike M. Mar 23 '17 at 00:12
  • I want the behavior even when there is a single item in the list. Whenever I touch the screen, the scroll should appear and when i dont touch it should hide or fade – Diwesh Saxena Mar 23 '17 at 00:18
  • Oh, I see what you mean. Um, why? That is, why would you want to give the user a visual indication that the `ListView` is scrollable when it's not? – Mike M. Mar 23 '17 at 00:20
  • Seems weird from a developer's view , but it's a design requirement, asked of me – Diwesh Saxena Mar 23 '17 at 00:22
  • Ah, understood. Well, unfortunately, I don't believe you're going to be able to do that with the standard attributes. I've a feeling that it'll require reflection to fiddle with `ListView`'s internals. – Mike M. Mar 23 '17 at 00:24

1 Answers1

0

In your theme make the following override:

<style name="Theme.App" parent="android:Theme.Light">
    <item name="android:fadeScrollbars">true</item>
 </style>

See here the first answer:

Autohide scrollbars when not scrolling in a ListView

Note: Fading scrollbar only appears if you have many items (more than a full screen). The alternative would be to do the opposite -> have scrollbar always visible (How to always show scrollbar)

The last possible solution would be to create a custom listview (extend from ListView) and somehow access the mechanism of the scrollbar

Community
  • 1
  • 1
ramden
  • 798
  • 1
  • 9
  • 25
  • Not working. Is this only when there are many items in the list for scroll to appear ? I want this behavior even when I have a single item in the list . – Diwesh Saxena Mar 23 '17 at 00:18
  • Tried doesn't seem to work. I still have one list item. But I added more code details. Appreciate your efforts to help – Diwesh Saxena Mar 23 '17 at 00:45
  • I added another sentence. From my experience such customizations are very complicated, have a huge effort and hurt a lot in general. With android it is mostly: "Take option A or B, C is conceptually possible and ... good luck with that, your android" :) – ramden Mar 23 '17 at 00:58