INNER CODE UNIT · Java

pxToDp

amitshekhariitbhu/awesome-android-complete-reference · others/util-classes/ViewUtils.java:19

    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(Context context, Drawable drawable) {
        if (drawable != null) {
            drawable.mutate();
            drawable.setColorFilter(ContextCompat.getColor(context, R.color.medium_gray), PorterDuff.Mode.SRC_ATOP);
        }
    }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…