When you need to set a pixel value for something like Paint.setTextSize but still want it be scaled based on the device, you can convert dp and sp values.
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, m...