https://kotlinlang.org logo
#compose
Title
# compose
b

Brendan Campbell-hartzell

07/09/2022, 3:01 AM
If I have a separate file with my compose code, is there a way to access the android R.xxx.whatever ids?
R
seems to be available, but it doesn't recognize
.string
or
.drawable
outside of an Activity class.
😶 3
I've also tried using
android.R
which makes
.string
and
.drawable
accessible, but I can't access any of my custom properties defined in the xml, like I could when inside an AppCompatActivity
s

Sean Proctor

07/09/2022, 3:16 AM
If you're trying to access stuff from your res directory, you need to import the R appropriate R package like:
import com.example.R
Inside composable functions you can use the function
stringResource
to get the string for a resource. You can find more information here: https://developer.android.com/jetpack/compose/resources
b

Brendan Campbell-hartzell

07/09/2022, 3:50 AM
Awesome. Thank you @Sean Proctor!
6 Views