Android搜索栏使用九个补丁图像设置自定义样式

Eri*_*hen 9 android progress fill seekbar nine-patch

我正在尝试创建一个自定义样式的搜索栏.我有两个9补丁图像,一个是灰色拉伸条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>
Run Code Online (Sandbox Code Playgroud)

我的问题是,不是栏填满我的拇指位置,整个栏一直是绿色(search_progress_bar图像).如何使用我自己的图像获得与Android的progress_horizo​​ntal.xml相同的效果(我不想使用形状来绘制我的栏)?

RaB*_*RaB 16

e_x_p的版本工作正常,但更简单的版本是

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:id="@android:id/background">
        <nine-patch android:src="@drawable/progressbar_bg" android:dither="true"/>
    </item>
    <item android:id="@android:id/progress">
        <clip xmlns:android="http://schemas.android.com/apk/res/android"
            android:clipOrientation="horizontal"
            android:gravity="left">
            <nine-patch android:src="@drawable/progressbar_status" android:dither="true"/>
        </clip>
    </item>

</layer-list>
Run Code Online (Sandbox Code Playgroud)


Eri*_*hen 11

我使用ClipDrawable解决了这个问题.这对我有用:

将@ drawable/search_progress_drawable设置为progressDrawable.

search_progress_drawable.xml:

<?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_clip"></item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

search_progress_clip.xml:

<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/search_progress_bar"
    android:clipOrientation="horizontal"
    android:gravity="left">
</clip>
Run Code Online (Sandbox Code Playgroud)