Code example for View

Methods: setBackgroundDrawable

0
    @SuppressWarnings("deprecation") 
    public static void setBackgroundForView(View view, Drawable drawable) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(drawable);
        } else { 
            view.setBackgroundDrawable(drawable);
        } 
    } 
 
    /** 
     * @see android.view.ViewTreeObserver#removeOnGlobalLayoutListener() 
     */ 
    @SuppressWarnings("deprecation") 
    public static void removeOnGlobalLayoutListener( 
            View view, ViewTreeObserver.OnGlobalLayoutListener listener) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
        } else { 
            view.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
        } 
    }