làm cách nào tôi có thể đặt ngón tay cái tùy chỉnh để cuộn nhanh trong chế độ xem danh sách.nhanh ngón tay cái tùy chỉnh cuộn
Trả lời
bạn có thể đặt đó vào style.xml
<style name="Theme_app" parent="@android:style/Theme.Holo.Light">
<item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
</style>
hơn tạo ra một xml trong drawable cho hình ảnh
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/fastscroll_thumb_pressed_holo" />
<item android:drawable="@drawable/fastscroll_thumb_default_holo" />
</selector>
Nếu bạn xem mã nguồn cho Android 2.2r1 (bản sửa đổi 1), có một lớp được gọi là android.widget.FastScroller
, có phương thức useThumbDrawable()
.
Tôi chỉ có downloaded the source from a blog called MobileBytes chứa nó, có thể bạn có thể nhập dữ liệu đó vào dự án của mình và triển khai? (Hoặc nâng cấp API của bạn để 2.2 r1)
Tôi đang sử dụng nhưng tôi không biết tại sao nó không hoạt động, vì vậy tìm kiếm trên web tôi tìm thấy here một giải pháp mã cứng, tôi không biết nếu nó hoạt động trên API cũ nhưng trong trường hợp của tôi đã được giải quyết vấn đề. Lưu ý rằng tôi đang sử dụng API 18 như mục tiêu và thiết bị có API 17 để kiểm tra.
mã:
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(<<your listView here>>);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.<<your thumb drawable here can be a selector>>);
f.set(o, drawable);
} catch (Exception e) {
e.printStackTrace();
}
cứng mã cho kitkat android (trường "mThumbDrawable" trong FastScroller (android kitkat) không tồn tại)
try {
java.lang.reflect.Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(root.findViewById(R.id.beam_contact_listview));
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
f = f.getType().getDeclaredField("mThumbImage");
} else {
f = f.getType().getDeclaredField("mThumbDrawable");
}
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.sv_fastscroll);
f.set(o, drawable);
} catch (Exception e) {
e.printStackTrace();
}
Thiết lập drawable từ phong cách là cách để đi. Tuy nhiên, nếu bạn muốn làm điều này theo lập trình ở đây là hai phương pháp hữu ích:
/**
* Set a ListView or GridView fast scroll thumb image.
*
* @param listView The {@link android.widget.ListView} or {@link android.widget.GridView}
* @param thumb The fast-scroll drawable
* @return {@code true} if successfully set.
*/
public static boolean setFastScrollThumbImage(AbsListView listView, Drawable thumb) {
try {
Field f;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
f = AbsListView.class.getDeclaredField("mFastScroll");
} else {
f = AbsListView.class.getDeclaredField("mFastScroller");
}
f.setAccessible(true);
Object o = f.get(listView);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
f = f.getType().getDeclaredField("mThumbImage");
f.setAccessible(true);
ImageView iv = (ImageView) f.get(o);
iv.setImageDrawable(thumb);
} else {
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = thumb;
f.set(o, drawable);
}
return true;
} catch (Exception ignored) {
}
return false;
}
/**
* Set a ListView or GridView fast scroll thumb color.
*
* @param listView The {@link android.widget.ListView} or {@link android.widget.GridView}
* @param color The color for the fast-scroll thumb
* @return {@code true} if successfully set.
*/
public static boolean setFastScrollThumbColor(AbsListView listView, int color) {
try {
Field f;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
f = AbsListView.class.getDeclaredField("mFastScroll");
} else {
f = AbsListView.class.getDeclaredField("mFastScroller");
}
f.setAccessible(true);
Object o = f.get(listView);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
f = f.getType().getDeclaredField("mThumbImage");
f.setAccessible(true);
ImageView iv = (ImageView) f.get(o);
iv.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_ATOP);
} else {
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
final Drawable drawable = (Drawable) f.get(o);
drawable.setColorFilter(color, android.graphics.PorterDuff.Mode.SRC_ATOP);
}
return true;
} catch (Exception ignored) {
}
return false;
}
- 1. Android SeekBar Tùy chỉnh ngón tay cái
- 2. Tùy chỉnh tìm kiếm - cách định vị đúng hình ảnh "ngón tay cái" tùy chỉnh?
- 3. Cách hiển thị ngón tay cái tùy chỉnh khi sử dụng fastScrollEnabled
- 4. Flex 4 Slider với hai ngón tay cái
- 5. Làm cách nào để đặt ngón tay cái trên thanh cuộn có lập trình trong Android?
- 6. Quy tắc không gian tên của ngón tay cái
- 7. Kích thước phần cứng - Quy tắc ngón tay cái
- 8. Ngón tay cái của Seekbar khi nhấp vào
- 9. kích thước thay đổi của ngón tay cái seekbar
- 10. Quy tắc ngón tay cái để viết hoa các chữ cái bằng ngôn ngữ lập trình
- 11. Trình đọc vân tay hoặc đầu đọc ngón tay
- 12. Android vẽ ngón tay cái tìm kiếm của riêng mình trong XML
- 13. Tắt di chuyển 2 ngón tay trong UIScrollView
- 14. Trạng thái đánh dấu UISlider với chiều rộng ngón tay cái khác so với bình thường
- 15. Chế độ ngón tay cái ARM: Kích thước mã không giảm
- 16. Phân trang UIScrollView bằng pan hai ngón tay và zoom
- 17. Android ListView alpha cuộn cho danh sách dài cuộn nhanh
- 18. Quy tắc ngón tay cái khi nào cần gọi ToList khi trả về kết quả LINQ
- 19. facebook rss - làm thế nào để tăng kích thước hình ảnh ngón tay cái?
- 20. Ngón tay cái trên các điểm góc đường không di dời các điểm
- 21. Android Seekbar - chỉ cho phép thay đổi bằng ngón tay cái?
- 22. Quy tắc ngón tay cái để đặt các lớp thể hiện mặt trước GAE
- 23. Làm cách nào để thay đổi màu của ngón tay cái trong thanh tìm kiếm?
- 24. Cử chỉ chụm ba ngón tay
- 25. cây Clojure ngón tay và flexvec
- 26. phát hiện ngón tay lên/xuống UITapGestureRecognizer
- 27. Làm thế nào để thay đổi kích thước của hình ảnh ngón tay cái của UISlider lập trình
- 28. Phát hiện swipe hai ngón tay của Safari
- 29. Cách vẽ hoa văn trên canvas khi kéo ngón tay
- 30. Thanh cuộn CSS tùy chỉnh cho Firefox
mThumbImage không phải là một Drawable trên KitKat +, nó là một ImageButton. –
@JaredRummler cảm ơn sự giúp đỡ –