hdodenhof / CircleImageView

A circular ImageView for Android
Apache License 2.0
14.55k stars 3.11k forks source link

border is disappear when setting border programmatically #399

Closed taehee28 closed 4 years ago

taehee28 commented 4 years ago

Hi! First, thanks for this useful library.

I have a small problem of using it, however. I used these setBorderWidth() and setBorderColor() method in code for changing border setting in runtime. But, in actual running time, border was just disappear when called those method. Why it happens??

Or, is there any good way to change border when CircleImageView clicked to use selector or something?

Waiting for answer

hdodenhof commented 4 years ago

Hi @theeeeeee,

what you are trying to do should work. Can you post the code you are using so I can have a look?

For another approach to implement a selector have a look at https://github.com/hdodenhof/CircleImageView/issues/153#issuecomment-249692049 - maybe you can adapt that to your needs.

taehee28 commented 4 years ago

Thanks for answer!

I'll refer to the link you attached

Here's my code

public void onClick(View v) {
// It called CircleImageView clicked

    ...    

    if(!v.isSelected) {
        petProflView.setBorderColor(0xFFCB33);
        petProflView.setBorderWidth(convertToPX(2));
    }

    ...

}

...

// Is that right that setBorderWidth()'s int parameter means PX? So, I made converting DP to PX method
private int convertToPX(int dp) {
    return (int)(dp * mDensity + 0.5);
}

CircleImageView's border is already set in xml

CircleImageView had border when Activity created, but it clicked and codes are worked and then border is disappear Is there any mistake in my code?

hdodenhof commented 4 years ago

setBorderColor expects a ColorInt - try this: petProflView.setBorderColor(Color.parseColor("#FFCB33")).

You are correct about setBorderWith - it expects PX.

taehee28 commented 4 years ago

Wow... it works perfectly...... Thanks a lot about your answer!!!!