【问题标题】:How to customize the look of a SeekBar in Android?如何在 Android 中自定义 SeekBar 的外观?
【发布时间】:2013-07-05 04:06:50
【问题描述】:

我在我的应用程序中使用了SeekBar,我想对其进行一些自定义。我已经想出了如何更改拇指和背景的Drawable

我的问题是如何更改SeekBar 的大小?如果我只是改变SeekBar like this, theViewis only clipped and it only shows the top piece of theSeekBar`的高度:

<SeekBar
   android:layout_height="10dip"
   style="@style/seekbar_style" />

如何更改Seekbar 的整体大小?我希望它比标准的SeekBar 更薄。

【问题讨论】:

标签: android seekbar


【解决方案1】:

您确实拥有相当于搜索栏的进度条:

  <style name="Widget.SeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:minHeight">20dip</item>
    <item name="android:maxHeight">20dip</item>
    <item name="android:thumb">@android:drawable/seek_thumb</item>
    <item name="android:thumbOffset">8px</item>
    <item name="android:focusable">true</item>
  </style>

因此,您可能希望通过定义自己的样式来覆盖所有这些并按照自己的方式进行操作,就像您对标题栏所做的那样。

【讨论】:

  • 这对我有用并展示了如何更改“拇指”图像(我只是不知道“拇指偏移”是做什么用的)
  • @RichardLeMesurier thumbOffset 只是拇指和搜索栏本身边缘之间的一个看不见的“间隙”。您将其设置为阻止拇指从两侧移动太远。
  • 如何更改“拇指”图像
  • @mohitum007 拇指图像被以下项更改:@android:drawable/seek_thumb
【解决方案2】:

我不确定 Seekbars,但 Progressbars 可以通过使用自定义样式(在您的 styles.xml 中定义)来自定义,如下所示:

<style name="MyCustomProgressStyle">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/custom_progress_drawable</item>
    <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
    <item name="android:minHeight">10dip</item>
    <item name="android:maxHeight">10dip</item>
</style>

然后您可以根据android系统的progress_horizontal.xml(在AOSP checkoutframeworks/base/core/res/drawable文件夹中)设置自定义drawable。这是来自开源项目的an example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多