The resource cannot be found. Here is my resource:
dimens.xml
<resources>
<dimen name="recyclerview_padding">10dp</dimen>
</resources>
In my fragment I tried each of the following:
val padding = getResources().getDimension(R.dimen.recyclerview_padding) as Int
val padding = context.getResources().getDimension(R.dimen.recyclerview_padding) as Int
val padding = activity.getResources().getDimension(R.dimen.recyclerview_padding) as Int
I also tried cleaning my project but this did not work.
This is how you should get the value
<resources>
<dimen name="recyclerview_padding">10dp</dimen>
</resources>
dimens.xml
val dimenFromXml = resources.getDimension(R.dimen.recyclerview_padding) // Int
It will be in Float by default
or you can use getDimensionPixelOffset which will convert it to Int
val dimenFromXml = resources.getDimensionPixelOffset(R.dimen.recyclerview_padding) // Float
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With