Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:04:40+00:00 2026-05-31T04:04:40+00:00

so i have a Layer-List with an Item with a shape and a solid

  • 0

so i have a Layer-List with an Item with a shape and a solid color. Now i want to change this color inside my code.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <clip>
            <shape android:id="@+id/seekbar_shape_color">
                <solid android:color="#FFD00000" />
            </shape>
        </clip>

    </item>
</layer-list>

i tryed getting the LayerDrawable and requesting the first item, now iam stuck getting the clipDrawable and finally get the ShapeDrawable

LayerDrawable sd = (LayerDrawable) v.getResources().getDrawable(R.drawable.seekbar_progress_bg);
((ClipDrawable) sd.getDrawable(0)).get..();

my other approach was to get the ShapeDrawable and setting the color with colorFilter but that doesnt work either.

ShapeDrawable sd = (ShapeDrawable) v.getResources().getDrawable(R.id.seekbar_shape_color);
sd.setColorFilter(R.color.cold_color,PorterDuff.Mode.MULTIPLY);

edit: ok so i developed a new plan
i tryed to use a LevelList like

 <level-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:maxLevel="0" android:drawable="@color/hot_color">
    </item>
    <item android:maxLevel="1" android:drawable="@color/cold_color">
    </item>
</level-list>

i think the default value for Level is 0 but i dont get the progressbar displayed with the LevelList.
Also i dont know on which element i have to set the setLevel()

        holder.progressbar.getBackground().setLevel(0);
        holder.progressbar.getIndeterminateDrawable().setLevel(0);
        holder.progressbar.getProgressDrawable().setLevel(0);

this calls give me strange results like only fresh progressbar items getting 100% progress coloration, smells like caching problem.

hope somebody can enlighten me how to use the LevelList properly on an LayerList for a Progressbar
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:04:41+00:00Added an answer on May 31, 2026 at 4:04 am

    I know this question is a few months old but I was able to get a level-list working with a progress bar.
    The trick is to assign your levels values between 0 and 10,000
    In my particular example I had 3 levels (red/yellow/green) used to represent battery life.

    Here is how I did it:

    res/drawable/progress_horizontal_yellow.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">
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#ff9d9e9d"
                        android:centerColor="#ff5a5d5a"
                        android:centerY="0.75"
                        android:endColor="#ff747674"
                        android:angle="270"
                />
            </shape>
        </item>
    
        <item android:id="@android:id/secondaryProgress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                            android:startColor="#80ffd300"
                            android:centerColor="#80ffb600"
                            android:centerY="0.75"
                            android:endColor="#a0ffcb00"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    
        <item android:id="@android:id/progress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                            android:startColor="#ffffd300"
                            android:centerColor="#ffffb600"
                            android:centerY="0.75"
                            android:endColor="#ffffcb00"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    </layer-list>
    

    res/drawable/progress_horizontal_red.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">
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#ff9d9e9d"
                        android:centerColor="#ff5a5d5a"
                        android:centerY="0.75"
                        android:endColor="#ff747674"
                        android:angle="270"
                />
            </shape>
        </item>
    
        <item android:id="@android:id/secondaryProgress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                            android:startColor="#80ffd300"
                            android:centerColor="#80ffb600"
                            android:centerY="0.75"
                            android:endColor="#a0ffcb00"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    
        <item android:id="@android:id/progress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                            android:startColor="#ffff0000"
                            android:centerColor="#ff990000"
                            android:centerY="0.75"
                            android:endColor="#ffff0000"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    
    </layer-list>
    

    res/drawable/progress_horizontal_green.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">
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#ff9d9e9d"
                        android:centerColor="#ff5a5d5a"
                        android:centerY="0.75"
                        android:endColor="#ff747674"
                        android:angle="270"
                />
            </shape>
        </item>
    
        <item android:id="@android:id/secondaryProgress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                            android:startColor="#80ffd300"
                            android:centerColor="#80ffb600"
                            android:centerY="0.75"
                            android:endColor="#a0ffcb00"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    
        <item android:id="@android:id/progress">
            <clip>
                <shape>
                    <corners android:radius="5dip" />
                    <gradient
                            android:startColor="#ff00ff00"
                            android:centerColor="#ff009900"
                            android:centerY="0.75"
                            android:endColor="#ff00ff00"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    </layer-list>
    

    res/drawable/battery_charge_fill.xml

    <?xml version="1.0" encoding="utf-8"?>
    <level-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:maxLevel="2999" android:drawable="@drawable/progress_horizontal_red" />
        <item android:maxLevel="4999" android:drawable="@drawable/progress_horizontal_yellow" />
        <item android:maxLevel="10000" android:drawable="@drawable/progress_horizontal_green" />
    </level-list>
    

    Then in the layout file my progress bar declaration was like this:

    <ProgressBar android:max="100" 
        android:progress="60"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:id="@+id/BatteryLevelProgress"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:progressDrawable="@drawable/battery_charge_fill"   />
    

    Then in java:

    //progress is between 0 and 100 so set level of drawable to progress * 100
    Drawable batteryProgressD = batteryProgressBar.getProgressDrawable();
    batteryProgressD.setLevel(progress*100);
    batteryProgressBar.setProgress(progress);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following drawable set as a background: <?xml version=1.0 encoding=utf-8?> <layer-list xmlns:android=http://schemas.android.com/apk/res/android>
I have this in res/values/styles.xml <style name=ListViewRowBorder > <item name=android:width>1dp</item> <item name=android:color>@color/listview_row_stroke_color</item> </style> I
i have this code: ArrayList list = new ArrayList(); foreach (DataRow dataR in prenume.Rows)
If you have a simple 2 layer list like so: <ul> <li><a href='#'>Item 1</a></li>
I have a problem with IE. I have a layer that has this style
I have a Div layer like this ... <style type=text/css> <!-- #newImg { position:absolute;
I have an unordered list, each list item has an id (id=6~OriginalName) - when
I posted a question about this earlier, but I have more information now and
How do we use a layer-list as a drawable for a button. I have
I have a listbox like so: list.DataSource = bindingSource; list.DisplayMember = column_name; Later I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.