> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stringboot.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Basic Usage

> Learn how to use Stringboot in your Android app

***

Stringboot provides multiple ways to access your strings, depending on your UI framework.

## XML Layouts (Declarative)

For traditional Android Views, you can use the `android:tag` attribute to bind a view to a string key.

<Steps>
  <Step title="Add Tag">
    Add the `android:tag` attribute to your TextView:

    ```xml theme={null}
    <TextView
        android:id="@+id/tvWelcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/default_welcome"
        android:tag="welcome_message" />
    ```
  </Step>

  <Step title="Apply Tags">
    Call `applyStringbootTags()` in your Activity or Fragment:

    ```kotlin theme={null}
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        // Apply strings to all tagged views
        binding.root.applyStringbootTags()
    }
    ```
  </Step>
</Steps>

## Kotlin (Programmatic)

You can fetch strings programmatically using `StringProvider`.

### Suspend Function

Use `get()` inside a coroutine for one-off fetching:

```kotlin theme={null}
lifecycleScope.launch {
    val text = StringProvider.get("welcome_message")
    binding.tvWelcome.text = text
}
```

### Reactive Flow

Use `getFlow()` to automatically update the UI when the string changes (e.g., language switch or remote update):

```kotlin theme={null}
lifecycleScope.launch {
    StringProvider.getFlow("welcome_message")
        .collect { text ->
            binding.tvWelcome.text = text
        }
}
```

## Jetpack Compose

For Jetpack Compose, use the `rememberStringboot` state or `StringbootText` composable (if available in your version).

```kotlin theme={null}
@Composable
fun WelcomeScreen() {
    // Reactive string state
    val welcomeMessage by StringProvider.getFlow("welcome_message")
        .collectAsState(initial = "Loading...")

    Text(text = welcomeMessage)
}
```

## Changing Language

To switch the language of the app at runtime:

```kotlin theme={null}
lifecycleScope.launch {
    // 1. Set new locale
    StringProvider.setLocale("es")
    
    // 2. (Optional) Force refresh to ensure latest strings
    StringProvider.refreshFromNetwork("es")

    // 3. Re-apply tags (for XML views)
    binding.root.applyStringbootTags()
}
```

<Note>
  `StringProvider.setLocale` updates the internal state. Reactive flows (Compose/Flow) will update automatically. For XML views, you must call `applyStringbootTags()` again.
</Note>
