Questions tagged [gradientdrawable]
32 questions
7
votes
3 answers
How to set TopLeftRadius and BottomLeftRadius for a GradientDrawable programmatically in Android
I have a ShapeDrawable . I want to set the CornerRadius (TopLeftRadius & BottomLeftRadius) programmatically.
Below is my xml
-

Sasank Sunkavalli
- 3,864
- 5
- 31
- 55
5
votes
3 answers
Android RecyclerView not changing background color on first item programmatically
I'm creating a list with a RecyclerView.
Every list item is a post from a user (Right now hard coded).
The background for every post is loaded from a layer-list XML file in the drawable folder.
Everything is working as intended with the texts etc.…

MisseMask
- 419
- 1
- 6
- 18
3
votes
3 answers
Setting Stroke on GradientDrawable Android
I am creating a custom Button and I am using the Drawable.setTintList to have colors for default,pressed and disabled states.
I want to actually add a border to the button, which I am trying by doing:
val d =…

pixelWorld
- 329
- 2
- 17
3
votes
0 answers
How to alter LayerDrawable within ImageView?
I'm adding a couple of ImageView to a LinearLayout programmatically, those ImageView have its src set to R.drawable.rectangle.
I'm trying to create a rectangle with solid color that has a border only to the left.
R.drawable.rectangle looks like…

maraujop
- 4,472
- 2
- 36
- 40
2
votes
0 answers
setGradientCenter (gradientDrawable.setGradientCenter) is not working in GradientDrawable
I am creating GradientDrawable and it's working fine. But now I need to give centerX and centerY position of GradientDrawable and I am giving with below code
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColors(new…

Bhaven Shah
- 692
- 1
- 5
- 18
2
votes
1 answer
Programmatically setting a shape color for a custom view
I've made a custom spinner and I'm trying to change background of a layout in a custom view programmatically. I tried a lot to change layout background with this method but it doesn't work. How can I set background drawable like xml codes?
Thanks in…

Mohsen Hatami
- 317
- 3
- 14
2
votes
0 answers
How to set Random GradientDrawable Color programmatically - Android
I have a problem with ProgressBar. When i press the button "Start" Random function choose one color from array, but only the first color is set as "background", when i click one more time new color is choose but not set as background. When i exit…

Icero
- 81
- 11
2
votes
1 answer
How to get Colors from Gradientrawable?
How it is possible to get Gradientrawable colors set by setColors(@ColorInt int[] colors) ?
Any help will be appricated.

TooCool
- 10,598
- 15
- 60
- 85
1
vote
1 answer
1
vote
0 answers
Why ColorStateList doesn't work with GradientDrawable?
I'm trying to set TestView background with GradientDrawable that is set for different states.
When using methods: setStroke and setColor (that gets ColorStateList) for a GradientDrawable it seems that the ColorStateList is being ignored.
For the…

Eitanos30
- 1,331
- 11
- 19
1
vote
0 answers
Set different corner radius for an ImageView programmatically
I'm creating ImageView programmatically and I am trying to set different corner radius for each corner:
val imageView = ImageView(context)
imageView.setImageDrawable(context.getDrawable(R.drawable.ic_launcher_background))
imageView.clipToOutline =…

Yanay Hollander
- 327
- 1
- 5
- 19
1
vote
1 answer
why does gradientdrawable.setBackground makes my app crash?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE);
drawable.setStroke(3,…

Jarrel Karl
- 15
- 4
1
vote
1 answer
GradientDrawable created programmatically: setSize and setGradientCenter methods do not work
I'm trying to set a gradient to my toolbar but it seems like setSize and setGradientCenter do not work.
I need to create it dynamically because the center and height of the gradient vary depending on the values I get from a CMS, but I am unable to…

moyo
- 1,312
- 1
- 13
- 29
1
vote
1 answer
How to show Android SeekBar progressChanged value inside SeekBar thumb?
I want to show the value of the current progress point in the thumb of an Android SeekBar. This is what I have tried so far:
SeekBar progBar = (SeekBar)FindViewById(Resource.Id.seekBar1);
progBar.ProgressChanged += (object sender,…

Israel Eruoghene
- 89
- 2
- 14
1
vote
0 answers
Custom GradientDrawable doesn't work on Android Lollipop
I want to use RingDrawable in my android application (no xml).
I found this code RingDrawable.java, but it doesn't work on Android Lollipop. There is simply no effect at all.
Could you tell me please how to improve this?
Thank you!
public class…

Huitarheroherohero
- 315
- 1
- 4
- 11