0

Hi i want to create a viewpager so i follow this tutorial : https://blog.mindorks.com/android-viewpager-in-kotlin. But when i try to set up the array of color in res.colors :

<array name=”bg_color”>
        <item name=”bg_screen1">#f64c73</item>
        <item name=”bg_screen2">#20d2bb</item>
        <item name=”bg_screen3">#3395ff</item>
        <item name=”bg_screen4">#c873f4</item>
    </array>

This doesn't compile, i got Attribute value expected on = of the first line. And i got type attribute should be define on all other lines. I assume that i should define a type of the array, but which type should i use for colors? and how to declare it ?

EDIT

To use it you have to declare and IntArray then select the good position :

val bg_color = resources.getIntArray(R.array.bg_color)
webView.setBackgroundColor(bg_color[pos])

Exemple for a web view where pos is an int

2 Answers 2

3

I think you copy paste code from that tutorial and because of that issue happens for " " . Please add below code .

<array name="bg_color">
    <item name="bg_screen1">#f64c73</item>
    <item name="bg_screen2">#20d2bb</item>
    <item name="bg_screen3">#3395ff</item>
    <item name="bg_screen4">#c873f4</item>
</array>
Sign up to request clarification or add additional context in comments.

1 Comment

Ok you right it's seem that the copy from the tutorial made the error. Thanks you fixed it
3

Don't give a name to each row, it's an array, not a map:

 <string-array name=”bg_color”>
            <item>#f64c73</item>
            <item>#20d2bb</item>
            <item>#3395ff</item>
            <item>#c873f4</item>
        </string-array>

2 Comments

And how can i acces it afterward?
String[] colors = getResources.getStringArray(R.array.bg_color);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.