Android 搜索栏使用九个补丁图像设置自定义样式
我正在尝试创建一个自定义样式的搜索栏。 我有两个九补丁图像,一个是灰色拉伸条 search_progress.9.png (背景色),另一个是绿色拉伸条 search_progress_bar.9.png (前景色)。
我使用这个xml作为我的seekbar的progressDrawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/search_progress"></item>
<item android:id="@android:id/progress" android:drawable="@drawable/search_progress_bar"></item>
</layer-list>
我的问题是,整个栏一直是绿色的(search_progress_bar图像),而不是填充到我的拇指位置。如何使用我自己的图像获得与Android的progress_horizontal.xml相同的效果(我不想使用形状来绘制我的条形图)?
I am trying to create a custom-styled seekbar.
I have two nine-patch images one is a gray stretching bar search_progress.9.png (background color) and the other is a green stretching bar search_progress_bar.9.png (foreground color).
I use this xml as my seekbar's progressDrawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/search_progress"></item>
<item android:id="@android:id/progress" android:drawable="@drawable/search_progress_bar"></item>
</layer-list>
My problem is that, instead of the bar filling up to my thumb position, the entire bar is green all the time (search_progress_bar image). How can I get the same effect as Android's progress_horizontal.xml with my own images (I do not want to use shapes to draw my bar)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
e_x_p 的版本工作得很好,但更简单的版本是
e_x_p's version works just fine but the even simpler version is
我使用 ClipDrawable 解决了这个问题。
这对我有用:
将@drawable/search_progress_drawable设置为progressDrawable。
search_progress_drawable.xml:
search_progress_clip.xml:
I solved this problem using a ClipDrawable.
This is what worked for me:
Set @drawable/search_progress_drawable as the progressDrawable.
search_progress_drawable.xml:
search_progress_clip.xml: