简体   繁体   中英

How to get a resource's path from the app using an Android Library?

I'm using an Android Library (SDK A) and it has a customize option.

This option is used like this example below:

val sdk = SDK_A()
sdk.customizeFont("font/myFont.ttf")
sdk.show()

It means this library will look for "myFont.ttf" inside fonts folder to show something using my custom font.

My main goal is to make a new Android Library (SDK B) that uses this library and let users of my library have access to this customisation, they will need to place their custom fonts somewhere my library can access.

My library should be used like this:

val sdk = SDK_B()
sdk.customizeFont("font/myFont.ttf") // it could have another approach, like resource id or something like this
sdk.show()

Summing up, users of SDK B will have a custom font and will set it using sdk.customizeFont method from SDK B, SDK B will set this same font using sdk.customizeFont method of SDK A.

I cannot change SDK A, I can make changes to SDK B and tell users how to use it.

SDK A: Needs to use some path like "font/myFont.ttf" to know where the font is.

SDK B: Needs to know where the font is to set the path on SDK A, doesn't need to have the same approach.

Anyone have a good idea on how to solve it?

Thanks to CommonsWare :

To be clear, the font file goes in main/assets/font/myFont.ttf in your module. You would then pass font/myFont.ttf to setTextFontName() .

On my test app using SDK B, I placed myFont.ttf in app/main/src/main/assets/font and set it using sdk_b.setTextFontName("font/myFont.ttf") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM