Add border on View programmatically

Viewed 26

What I am trying to do is add a border around the View, I tried this https://stackoverflow.com/a/29414975/14798043 but it doesn't work in Material Button. What I want is something with high compatibility. Is there such way to do it?

here is what i tried

    LayerDrawable newDrawable;
    GradientDrawable border = new GradientDrawable();
    border.setStroke(1, 0xFF000000); //black border with full opacity
    Drawable oldDrawable = view.getBackground();
    newDrawable = new LayerDrawable(new Drawable[]{
        oldDrawable,
        border
    });
    view.setBackground(newDrawable);

0 Answers
Related