Android Question Rounded corner of pressedDrawable

cambopad

Active Member
Licensed User
Longtime User
Hi, all B4A devs

How can I create a rounded corner of pressedDrawable that I get through the following code:

B4X:
    Dim pressedDrawable As Object
    Dim r As Reflector
    Dim idPressed As Int
       idPressed = r.GetStaticField("android.R$drawable", "list_selector_background")
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    pressedDrawable = r.RunMethod2("getDrawable", idPressed, "java.lang.int")


I tried to convert it to rounded corner color drawable by using the following code:


B4X:
Dim Rounded_pressedcolor As ColorDrawable
    Rounded_pressedcolor.Initialize(pressedDrawable,40dip)


But it caused the following error:

B4X:
java.lang.NumberFormatException: Invalid double: "android.graphics.drawable.StateListDrawable@16b4d1ec"

Your help is really appreciated!
 

cambopad

Active Member
Licensed User
Longtime User
Thanks for you advice, but my purpose is to convert that drawable to a rounded corner drawable. I cannot find a way to round its corner besides using a colordrawable. However, just like you said, this colordrawable is expecting a color value! Is there any way I can do that?
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
What kind of veiw are you wanting to achieve? Maybe there is a better way to do this?
It looks to me like you are getting the Drawable object from a ListVeiw, is that correct? Are you wanting a ListVeiw which has rounded corners?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The drawable returned from this code is a StateListDrawable. This means that it holds a set of other drawables.

You can use the debugger to examine this object and see the types of drawables inside the StateListDrawable. If there is a color drawable inside then you might be able to get its color. Overall it is a bit complicated and also fragile as different devices use different default drawables.
 
Upvote 0

cambopad

Active Member
Licensed User
Longtime User
What kind of veiw are you wanting to achieve? Maybe there is a better way to do this?
It looks to me like you are getting the Drawable object from a ListVeiw, is that correct? Are you wanting a ListVeiw which has rounded corners?

Yes, you are correct. I am customizing the Custom ListView. I already made the corner of each item in the list rounded, but I cannot make the corner of presseddrawable rounded at all.
 
Upvote 0

cambopad

Active Member
Licensed User
Longtime User
If there is a color drawable inside then you might be able to get its color. Overall it is a bit complicated and also fragile as different devices use different default drawables.

As it will be different based on the devices, I think I should look for the other alternative solutions besides using presseddrawable!
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
Yes, you are correct. I am customizing the Custom ListView. I already made the corner of each item in the list rounded, but I cannot make the corner of presseddrawable rounded at all.
I'd like to help but I'm still not sure I understand why you are having a problem. If you are using the CustomListView then you can apply your own StateListDrawable to each item and have them however you want.
Would it be possible to provide a small sample of the list as you have it now and maybe a screenshot highlighting what you want changed? There's always a way, sometimes we just need to be a little creative
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…