setBackgroundDrawable() deprecated

前端 未结 11 1631
长发绾君心
长发绾君心 2020-12-03 00:18

So my sdk goes from 15 to 21 and when I call setBackgroundDrawable(), Android Studio tells me that it\'s deprecated.

I thought of going around it using:

11条回答
  •  一生所求
    2020-12-03 00:58

    It's funny because that method is deprecated, but if you look at the Android Source Code you'll find this:

       /**
         * Set the background to a given Drawable, or remove the background. If the
         * background has padding, this View's padding is set to the background's
         * padding. However, when a background is removed, this View's padding isn't
         * touched. If setting the padding is desired, please use
         * {@link #setPadding(int, int, int, int)}.
         *
         * @param background The Drawable to use as the background, or null to remove the
         *        background
         */
        public void setBackground(Drawable background) {
            //noinspection deprecation
            setBackgroundDrawable(background);
        }
    

提交回复
热议问题