How to handle a fast scroller on Lollipop 5.1?

Background

I made a small library that shows how to simulate the style of the app for contacts with Android Lollipop, here .

Problem

It seems that on Android 5.1 the fast scroller looks very different than the previous one, and it is too close to the right, so it is difficult to use.

Android 4.4 Screenshot:

enter image description here

Here is a screenshot on Android 5:

enter image description here

and on Android 5.1:

enter image description here

What i found

I tried to look at the all β€œwhat's new” section of Android 5.1, as well as in some related class documents, but I did not find anything special except β€œ setFastScrollStyle ”. However, I could not find any explanation of how to use it (plus this is from API 21, so this may not be the reason).

Question

How to make a quick scroller a little to the left so that it is easier to touch?

How do you use setFastScrollStyle? Is there a tutorial for this?

+6
source share
2 answers

I had the same problem, and after several hours of research, I came up with a solution. This AOSP commit helped me the most, it shows the changes made to the scrollbar in Android 5.1 (SDK 22): Update scrollbars according to material specification

There are two possibilities:

enter image description here

A: use a new style and add an addition

This will keep the same new rectangle from API 21 (Android 5.1), but add some additions left and right.

1: Copy the fastscroll_thumb_material.xml file to the folder with your hair

This should be the content (deleted AOSP comments to save space):

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape android:tint="?attr/colorControlActivated" android:shape="rectangle"> <solid android:color="@android:color/white" /> <size android:width="8dp" android:height="48dp" /> </shape> </item> <item> <shape android:tint="?attr/colorControlNormal" android:shape="rectangle"> <solid android:color="@android:color/white" /> <size android:width="8dp" android:height="48dp" /> </shape> </item> </selector> 

2: edit the theme

Add the following element to your topic. I think you can put this in style and use it with setFastScrollStyle , but I find it easier.

 <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_material</item> 

3: Edit fastscroll_thumb_material.xml

You can edit it to your liking, but I did the following, which adds 8dp to the left and right of the scroll bar. I added a list of layers and an element around each shape and added android:right="8dp" and android:left="8dp" to the new element. I tried to add this to the original elements, but it didn’t work, and there were no additions to the form.

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <layer-list> <item android:right="8dp" android:left="8dp"> <shape android:tint="?attr/colorControlActivated" android:shape="rectangle"> <solid android:color="@android:color/white" /> <size android:width="8dp" android:height="48dp" /> </shape> </item> </layer-list> </item> <item> <layer-list> <item android:right="8dp" android:left="8dp"> <shape android:tint="?attr/colorControlNormal" android:shape="rectangle"> <solid android:color="@android:color/white" /> <size android:width="8dp" android:height="48dp" /> </shape> </item> </layer-list> </item> </selector> 

B: change the scrollbar to old style

This will use the API 21 style, Android 5.0

1: add old drawings to the project

You can download them from the above (fastscroll_thumb_mtrl_alpha.png and fastscroll_track_mtrl_alpha.9.png), but I also linked them, you can also download them from my Google Drive .

2: add fastscroll_thumb_material.xml to your drawings

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <bitmap android:src="@drawable/fastscroll_thumb_mtrl_alpha" android:tint="?attr/colorControlActivated" /> </item> <item> <bitmap android:src="@drawable/fastscroll_thumb_mtrl_alpha" android:tint="?attr/colorControlNormal" /> </item> </selector> 

3: add fastscroll_track_material.xml to your drawings

 <?xml version="1.0" encoding="utf-8"?> <nine-patch xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/fastscroll_track_mtrl_alpha" android:tint="?attr/colorControlNormal" /> 

4: edit your theme

Add the following element to your topic. I think you can put this in style and use it with setFastScrollStyle , but I find it easier.

 <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_material</item> <item name="android:fastScrollTrackDrawable">@drawable/fastscroll_track_material</item> 

Hope this helps to achieve your goal :)

+8
source

Why not install an add-on on the right side of your layout containing a ListView? Google web page @ setPadding () . Personally, I used android: paddingLeft for a similar problem like yours.

Another common trick is to add a (hidden) ImageView in the layout on the right side (horizontal orientation). ImageView will be hidden and size (width) can be set.

Glad to help frequent SO users, I hope I did. Regards, Tommy Qui

+1
source

Source: https://habr.com/ru/post/983801/


All Articles