update Background View Resource With Retained Padding - Android User Interface

Android examples for User Interface:View Padding

Description

update Background View Resource With Retained Padding

Demo Code


//package com.java2s;
import android.view.View;

public class Main {
    public static void updateBackgroundResourceWithRetainedPadding(
            View view, int resourceID) {
        int bottom = view.getPaddingBottom();
        int top = view.getPaddingTop();
        int right = view.getPaddingRight();
        int left = view.getPaddingLeft();
        view.setBackgroundResource(resourceID);
        view.setPadding(left, top, right, bottom);
    }//  ww  w .  jav a 2s  . c om
}

Related Tutorials