Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set SeekBar's progress color to transparent

Here is a picture of what I want to accomplish, where there is no progress color (transparent), with a solid grey background bar:

seekbar

I tried

android:progressTint="#00000000"

But that sets the whole bar (progress bar AND the back bar) to transparent.

I also tried:

android:progressDrawable="@drawable/customseekbar"

where customseekbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
    android:id="@android:id/background"
    android:drawable="@drawable/seekbar_background" />

<item android:id="@android:id/progress">
    <clip android:drawable="@drawable/seekbar_background" />
</item>

and seekbar_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="#FF555555" />
</shape>

but then I get this fat and ugly:

notwhatiwant

What am I doing wrong here? Thanks

like image 278
baekacaek Avatar asked Oct 28 '15 00:10

baekacaek


People also ask

How do I change the color of my SeekBar track?

If you are using default SeekBar provided by android Sdk then their is a simple way to change the color of that . just go to color. xml inside /res/values/colors. xml and change the colorAccent.

How do I customize SeekBar?

Now go to the activity_main. xml create a layout and inside the layout add a SeekBar. Specify the height width of SeekBar and the max progress that you want to use set progress to 0. This will create a customized Seekbar inside activity_main.

What is SeekBar ProgressBar?

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged. Clients of the SeekBar can attach a SeekBar.

How to implement SeekBar in android studio?

Step1: Create a new project. After that, you will have java and XML file. Step2: Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take. Assign ID to SeekBar And TextView.


1 Answers

How to Style a Seekbar in Android

Here you go, you need to do the following

Step 1:

In drawable, put "progress_bg.png" (find attached)

Step 2:

In drawable, create "myprogessbar_style.xml", and insert the following

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background"
          android:drawable="@drawable/progress_bg" />
    <item
        android:id="@android:id/secondaryProgress"
        >
        <scale
            android:drawable="@drawable/progress_bg"
            android:scaleWidth="100%"/>
    </item>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/progress_bg"/>

</layer-list>

Step 3:

Your seekbar

<SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_margin="10dp"
            android:indeterminate="false"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:progressDrawable="@drawable/myprogessbar_style"/>

Result

enter image description here

Attachment

enter image description here

P.S. Yes, it's not a transparency but the expected result

like image 146
Murtaza Khursheed Hussain Avatar answered Sep 24 '22 21:09

Murtaza Khursheed Hussain