B4A Library AndroidResources

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I got tired of looking these up when I needed them, so for those of you who want to use the Phone library's GetResourceDrawable method to retrieve a BitmapDrawable, here is a mnemonic constant list compiled from the Resource Drawable developer page cited in the first post.
 

Attachments

  • RD.bas
    10.7 KB · Views: 262

phukol

Active Member
Licensed User
Longtime User
Good day everyone. I want to change the color used in my CustomerListView. Its using the list_selector_background which is used in gingerbread and lower versions. I want to access the attribute "list_pressed_holo_dark" using Android Resources. How can i do this? The code is:
B4X:
idPressed = r.GetStaticField("android.R$drawable",  "list_selector_background")

i want it to use "list_pressed_holo_dark" but it will not work even if i type it directly and ive read i can access it using AndroidResources library
 

DonManfred

Expert
Licensed User
Longtime User
Any examples for using Formatting strings with parameters ?

Use GetAndroidString and do the formatting by yourself (replace %1 with value a, %2 with value b....
  • GetAndroidString (ResourceName As String) As String
    Get an android resource string by ResourceName.
    Returns Null if the String is not found.
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Try this:

B4X:
'RESOURCES

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <plurals name="message">
        <item quantity="one">You have one new message</item>
        <item quantity="other">You have %d new messages</item>
    </plurals>
</resources>

'JAVA

#if Java

public int getResourceId(String type, String name)
    {
        return BA.applicationContext.getResources().getIdentifier(name,    type, BA.packageName);
    }

    public String FormatPlural(int id, int count) {

        return BA.applicationContext.getResources().getQuantityString(id,  count, count);
    }

#End If

'B4A
Sub Activity_Create(FirstTime As Boolean)

   Private NativeMe As JavaObject
   NativeMe.InitializeContext
   Dim id As Int = NativeMe.RunMethod("getResourceId", Array("plurals","message"))
 
   Dim s As String = NativeMe.RunMethod("FormatPlural", Array(id,1))
   Log(s)

   Dim s As String = NativeMe.RunMethod("FormatPlural", Array(id,2))
   Log(s)

End Sub

'RESULTS
'You have one new message
'You have 2 new messages
 
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
Hello,

I know it's an old thread and an old library.
But still working even on B4A v10.60 !
I used it in an old project, but today when i tried to adapt it with xChart lib from Klaus i have an issue.
the example, if i use:
xChart1.YAxisName = AndroidResources3.GetApplicationString("chart_yAxis")
xChart1.XAxisName = AndroidResources3.GetApplicationString("chart_xAxis")
If ever there is a typo or an xml file isn't updated (outdated) it returns Null and give an error with other libraries.
It's possible to change that for an empty string ?

Thank you,
Laurent
 

DonManfred

Expert
Licensed User
Longtime User
xChart1.YAxisName = AndroidResources3.GetApplicationString("chart_yAxis")
B4X:
if AndroidResources3.GetApplicationString("chart_yAxis") <> null then
    xChart1.YAxisName = AndroidResources3.GetApplicationString("chart_yAxis")
end if
?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…