SoFunction
Updated on 2025-03-08

Android view changing background resources and padding disappears problem solution

Android view changing background resources and padding disappears problem solution

This requirement is generally not commonly used, but it is quite depressing to encounter it. This should be considered a bug in the SDK. The solution is to set the margins recorded before.
Then set it back.

Specific methods

/**
  * Setting does not change the background of padding
  * The problem of padding invalid after setting the background of Android
  *
  * @param view
  * @param resId
  * @autor wujiajun
  */ 
public static void setBackgroundResourceWithPadding(View view, int resId) { 
  int bottom = (); 
  int top = (); 
  int right = (); 
  int left = (); 
  (resId); 
  (left, top, right, bottom); 
} 

Thank you for reading, I hope it can help you. Thank you for your support for this site!