如何在 Android 中自定义 SeekBar 的外观?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3187154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to customize the look of a SeekBar in Android?
提问by Janusz
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.
我SeekBar
在我的应用程序中使用了 a ,我想对其进行一些自定义。我已经想出了如何更改Drawable
拇指和背景的。
My question is how to change the size of the SeekBar
? If I just change the height of the SeekBar like this, the
Viewis only clipped and it only shows the top piece of the
SeekBar`:
我的问题是如何更改SeekBar
? 如果我只是更改SeekBar like this, the
View is only clipped and it only shows the top piece of the
SeekBar`的高度:
<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
.
如何更改 的整体大小Seekbar
?我希望它比标准的要薄得多SeekBar
。
回答by Sephy
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.
因此,您可能希望通过定义自己的样式来覆盖所有这些并按照您的方式进行操作,就像您对标题栏所做的那样。
回答by Yoni Samlan
I'm not sure about Seekbars, but Progressbars can be customized by using a custom style (defined in your styles.xml) like so:
我不确定 Seekbars,但可以使用自定义样式(在你的 styles.xml 中定义)来自定义 Progressbars,如下所示:
<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 examplefrom an open-source project.
然后,您可以根据 android 系统progress_horizontal.xml
(它位于AOSP checkout的frameworks/base/core/res/drawable
文件夹中)设置自定义 drawable 。这是一个来自开源项目的示例。