2013-08-07 52 views
13

我想默认的Android搜索条个性化设置:自定义搜索栏绘制对象的Android

enter image description here

我看了大约九补丁图像,创造了6个PNG图像。前三个是为灰进度条(progressDrawable),如下图所示:

  1. 右图像

    enter image description here

  2. 中心图像

    enter image description here

  3. 左图像

    enter image description here

结果应该是:

enter image description here

蓝色图像表示的进展,并如下:

  1. 右图像

    enter image description here

  2. 中心图像

    enter image description here

  3. 左图

    enter image description here

和拇指如下:

enter image description here

我的问题是,我该如何使用9个修补图像生成自定义搜索条完全一样的第一张照片,我怎么能将此我的搜索条?

+0

我建议你检查由框架本身使用的可绘。你可以在你的android sdk目录中找到它们:'android-sdk-dir/platforms/platform-XX/data/res/drawable- * dpi'。查找名为scrubber_track * .9.png,scrubber_primary * .9.png,scrubber_secondary * .9.png和scrubber_control * .9.png(*为通配符)的九个补丁映像 – Karakuri

+0

您能否提供给我一个示例请 – Dimitri

+0

你可以将图像1,2和3合并成一个可绘制的九个修补程序 – pskink

回答

16

我认为它不应该是复杂的。您不必制作6张图片即可满足您的需求。只需为背景创建2个九块补丁即可。和thumb.png。这里是你的XML:

<SeekBar 
    android:id="@+id/my_seekbar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:progressDrawable="@drawable/seekbar_progress" 
    android:thumb="@drawable/thumb"> 
seekbar_progress

<?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> 

请记住,创造,所以它看起来像你想,当你thumb应该对上面的空白。 希望这有助于。

+0

谢谢progressbar_status是什么? – Dimitri

+0

这是'进度' - 蓝色图像在你的情况下 – boburShox

+0

谢谢你,我会尝试恢复。也如果我把空间与拇指它会创造额外的空间@top,也在底部我试过这个 – Dimitri

1

1)进入AndroidSDK - >工具和运行draw9patch.bat

,你会看到黑色窗口

2)拖动图片到窗口,并开始9补丁:

围绕你的图片开始打补丁

3)现在进入文件菜单并且点击保存9补丁...

最后提示:您的图片必须是。PNG格式,并且只包含内容而不是可用空间。例如我把你的照片保存在我的电脑里,看到你的照片的蓝色部分有很多未使用的空间。

现在应用到你的搜索条

只要按照上面的链接以及

Create Custom Slide Bar

对不起;我没有足够的信誉来插入图片

8

您可以使用Java代码自定义seekbar ...并添加图层列表作为drawables ...这段代码将帮助我,我希望。

1.LayerList绘制

<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item 
     android:id="@android:id/background"> 
     <nine-patch 
      android:src="@drawable/your_nine_patch_image" 
      android:tileMode="repeat"> 
     </nine-patch> 
    </item> 
    <item 
     android:id="@android:id/progress"> 
     <layer-list 
      xmlns:android="http://schemas.android.com/apk/res/android" > 
      <item> 
       <clip > 
        <bitmap 
         xmlns:android="http://schemas.android.com/apk/res/android" 
         android:src="@drawable/clipimage_for_progress" 
         android:tileMode="repeat"/> 
       </clip> 
      </item> 
     </layer-list> 
    </item> 
</layer-list> 

这将是你customSeekbar类,你可以使用此自定义搜索条在你的应用

public class CustomSeekbar { 
    public CustomSeekbar(Context context) { 
     super(context); 
     setCustomUI(); 
    } 

    public CustomSeekbar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     setCustomUI(); 
    } 

    public CustomSeekbar(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     setCustomUI(); 
    } 

    void setCustomUI() { 

     this.setProgressDrawable(getResources().getDrawable(
       R.drawable.yourBackground)); 
    } 
}