Android SeekBar [ProgressBar] style - how to set custom background drawable

你离开我真会死。 提交于 2019-12-25 11:48:08

问题


I want to make seekbar like this: http://img687.imageshack.us/img687/2371/volumec.png The thing is, that Ive already found customizing seekbars over here http://groups.google.com/group/android-developers/browse_thread/thread/be3fed0b4f766cc?pli=1 but the problem is, that I need **those gaps** between in my drawable and I dont know how to manage that. Would you be so kind some of you, I`ll appreciate it very much. Thanks in advance, wishing all the best!

this is my resources style.xml file that is applied to seekbar:

<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@drawable/seekbarcolors</item>
<item name="android:indeterminateDrawable">@drawable/seekbarcolors</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
<item name="android:thumbOffset">8px</item>
<item name="android:focusable">true</item>

and here is my @drawable/seekbarcolors:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
    <shape>
        <solid android:color="#ff0000" />
    </shape>
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <solid android:color="#00ff00" />
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <solid android:color="#0000ff" />
        </shape>
    </clip>
</item>


回答1:


A Seekbar is a pretty powerful widget. Ddo you want the user to be able to "seek" the volume here? It's not made to show progress with gaps.

What you need here (if you don't need to grab and seek the volume) is lots simpler. Create a single ImageView to the right of "Volume" in your sample pic. In your progress-watching AsyncTask, put code in onProgressUpdate() to change the shown image across 10 images - each the same as the last but with one more bar - as progress breaks each 10%. You can write code to put a single image times properly positioned across a space, but that is harder and buys you little.




回答2:


The thing is that i need to seek volume..as you can see, i' ve styled seekbar with my custom shape where colors are set Last thing i need to do is create repeatable shape with block of opacity 1 and block with opacity 0. How this can be done? I am new to android developmemt therefore not very smart with shapes :) thanks




回答3:


To change Volume bar colour in android In framework/core/res/res/layout change colour in volume_adjust.xml



来源:https://stackoverflow.com/questions/5024399/android-seekbar-progressbar-style-how-to-set-custom-background-drawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!