android / android-ktx

A set of Kotlin extensions for Android app development.
https://android.github.io/android-ktx/core-ktx/
7.47k stars 564 forks source link

TextView.setTextDimen #187

Open robertoestivill opened 6 years ago

robertoestivill commented 6 years ago

Useful method to set text size given a R.dimen resource

/**
 * Set this TextView text size with a R.dimen constant
 * 
 * @param dimen R.dimen reference
 */
fun TextView.setTextDimen(@DimenRes dimen: Int) {
  setTextSize(TypedValue.COMPLEX_UNIT_PX, context.resources.getDimension(dimen))
}

If agreed useful, I can submit the PR later.

daberni commented 6 years ago

Any problems when calling it setTextSize? Purpose should probably be clear by parameters.

robertoestivill commented 6 years ago

Not really. For some reason I thought there was a TextView.setTextSize(size:Int) method defined already, and that would be a problem.

jaredsburrows commented 6 years ago

@robertoestivill @daberni There is already: https://developer.android.com/reference/android/widget/TextView.html#setTextSize(float).

daberni commented 6 years ago

@jaredsburrows you are referencing it with float argument, the proposal is with int, so it shouldn't be a problem