inline fun View.sp(value: Int): Int = context.sp(value)
inline fun View.sp(value: Float): Int = context.sp(value)
Yet I get error Type mismatch: inferred type is Int but Float was expected on the last line:
val p = Paint()
p.textSize = sp(24)
Build: 3.0 Canary 9, AI-171.4220116, 201707262319, AI-171.4220116, JRE 1.8.0_152-release-884-b01x64 JetBrains s.r.o
Kotlin version 1.1.3-2
bennyl
2
I believe that the compiler complaining about attempting to assign an int to the field textSize
of type float
thanks! So it is a bug in the inlined fun? (Anko)
Paint.class has:
public void setTextSize(float textSize) {
Maybe diagnostics could be clearer? …but Float was expected by textSize ?
This funny code works 
p.textSize = sp(24.0f).toFloat()
HughG
4
Both of your functions return Int; shouldn’t the second return Float?
I suspect you are right, yet it might be some Android idiosyncrasy. So I am tagging this Android.
Anko has:
so it’s either bug in Anko or I am doing something wrong?
As per
https://developer.android.com/reference/android/widget/TextView.html#attr_android:textSize
May be a dimension value, which is a floating point number appended with a
unit such as “14.5sp”.