public class ViewUtils {
private ViewUtils() {
// This utility class is not publicly instantiable
}
public static float pxToDp(float px) {
float densityDpi = Resources.getSystem().getDisplayMetrics().densityDpi;
return px / (densityDpi / 160f);
}
public static int dpToPx(float dp) {
float density = Resources.getSystem().getDisplayMetrics().density;
return Math.round(dp * density);
}
public static void changeIconDrawableToGray(Contextcontext, Drawable drawable) {
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(ContextCompat.getColor(context,R.color.medium_gray),PorterDuff.Mode.SRC_ATOP);
}
}
}
public final class ViewUtils {
private ViewUtils() {
// This utility class is not publicly instantiable
}
public static float pxToDp(float px) {
float densityDpi = Resources.getSystem().getDisplayMetrics().densityDpi;
return px / (densityDpi / 160f);
}
public static int dpToPx(float dp) {
float density = Resources.getSystem().getDisplayMetrics().density;
return Math.round(dp * density);
}
public static void changeIconDrawableToGray(Contextcontext, Drawable drawable) {
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(ContextCompat.getColor(context,R.color.medium_gray),PorterDuff.Mode.SRC_ATOP);
}
}
}
dp2px
最新推荐文章于 2023-10-04 17:53:33 发布