我想为seekbar创建一个自定义拇指,应该如下所示:
一种解决方案可以是this one,其中png图片用于绘制拇指。
我认为应该可以只使用XML,因为它与这个拇指非常相似:
拇指.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:height="30dp" android:width="30dp"/>
<stroke android:width="18dp" android:color="#882EA5DE"/>
<solid android:color="#2EA5DE" />
<corners android:radius="1dp" />
</shape>
只需要添加第二个边框(周围的白色笔划),这样我就可以跳过以管理不同屏幕分辨率(hdpi/mdpi/xhdpi/xxhdpi)的所有图片。
我试过用不同形状的“椭圆形”和“环形”组合,但没有得到所需的结果。你怎么能做到?
最佳答案
我无法找到一个只使用xml的解决方案,这就是为什么我使用图片来解决这个问题,而this answer提供了一点帮助:
创建了一个拇指图像seekbar_thumb_icon.png
并以不同的分辨率保存在res/drawable-*
地图(hdpi/mdpi/xhdpi/xxhdpi)中。
为seekBar指定“android:thumb=”@layout/seekBar\u thumb“:ojit_pre
其他款式:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item>
<shape>
<size
android:height="30dp"
android:width="30dp" />
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:drawable="@drawable/balance_icon_48px"/>
</layer-list>
seekbar_style.xml
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@layout/seekbar_style"
android:thumb="@layout/seekbar_thumb" />
请参阅background.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent"
android:layout_width="match_parent">
<item android:id="@android:id/background"
android:drawable="@layout/seekbar_background" />
<item android:id="@android:id/progress">
<clip android:drawable="@layout/seekbar_progress" />
</item>
</layer-list>
见kbar_progress.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shape="line">
<stroke android:width="2dp" android:color="#868686"/>
<corners android:radius="1dp" />
</shape>