如何在 Android 中自定义 SeekBar 的外观?

发布于 2024-09-08 05:31:13 字数 398 浏览 2 评论 0原文

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

我的问题是如何更改 SeekBar 的大小?如果我只是像这样更改 SeekBar 的高度,View只会被裁剪,并且仅显示SeekBar`的顶部部分:

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

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

I use a SeekBar in my application and I would like to customize it a little bit. I already figured out how to change the Drawable for the thumb and for the background.

My question is how to change the size of the SeekBar? If I just change the height of the SeekBar like this, theViewis only clipped and it only shows the top piece of theSeekBar`:

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

How do I change the overall size of the Seekbar? I want it to be much thinner then the standard SeekBar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2024-09-15 05:31:13

您确实拥有与搜索栏的进度栏等效的内容:

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

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

You have the equivalent of this of the Progress Bar for the seekbar indeed :

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

So you might want to override all this and do it your way, as you would do it for the title bar, by defining your own style.

反差帅 2024-09-15 05:31:13

我不确定 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_horizo​​ntal.xml 设置自定义可绘制对象 (位于 AOSP 结账)。这是示例 来自开源项目。

I'm not sure about Seekbars, but Progressbars can be customized by using a custom style (defined in your styles.xml) like so:

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

Then you can set up a custom drawable based on the android system's progress_horizontal.xml (it's in the frameworks/base/core/res/drawable folder of an AOSP checkout). Here's an example from an open-source project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文