• Latest Code...

    Featured Post

    Implementing Hilt in a Kotlin Android Jetpack Compose Project with MVVM Architecture

     In modern Android development, maintaining a scalable codebase can be challenging, especially when it comes to dependency management. Hilt,...

    Read String and string array value from string.xml in android?

    A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings:
    String
    XML resource that provides a single string.
    String Array
    XML resource that provides an array of strings.
    Quantity Strings (Plurals)
    XML resource that carries different strings for pluralization.

    All strings are capable of applying some styling markup and formatting arguments. For information about styling and formatting strings, see the section about Formatting and Styling.

    String:

    <?xml version="1.0" encoding="utf-8"?>
        <resources>
            <string
                name="string_name">text_string</string>
        </resources>

    getting string like this on activity:

    String mess = getResources().getString(R.string.string_name);

    String Array:


    <string-array name="tabs_names"> 
    <item>My Tab 1</item>
    <item>My Tab 2</item>
    </string-array>

    getting string array like this on activity:

    String[] tab_names = getResources().getStringArray(R.array.tab_names);

    Happy Coding!!

    Contact Form

    Name

    Email *

    Message *