更改布局背景和状态栏颜色

时间:2018-05-13 11:25:05

标签: android

我制作了一个简单的单屏应用 我试图从11种颜色中随机改变布局的背景颜色 点击按钮,我知道如何使用随机方法,但无法弄清楚如何在数组中存储11种颜色以及如何访问它们 This like may tell you what i want 这是我想改变颜色

的布局
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
tools:context=".MainActivity"
android:id="@+id/bg"
tools:layout_editor_absoluteY="25dp">

这是我的colorarray.xml

<?xml version="1.0" encoding="utf-8"?>

<!--bg color-->
<color name="color1">#7e3ff2</color>
<color name="color2">#ff6e39</color>
<color name="color3">#f2366e</color>
<color name="color4">#e800c3</color>
<color name="color5">#b402ee</color>
<color name="color6">#01abff</color>
<color name="color7">#00d5a0</color>
<color name="color8">#00d5c7</color>
<color name="color9">#7763cf</color>
<color name="color10">#e3e17c</color>
<color name="color11">#c7984b</color>

<array name="background">
    <item>@color/color1</item>
    <item>@color/color2</item>
    <item>@color/color3</item>
    <item>@color/color4</item>
    <item>@color/color5</item>
    <item>@color/color6</item>
    <item>@color/color7</item>
    <item>@color/color8</item>
    <item>@color/color9</item>
    <item>@color/color10</item>
    <item>@color/color11</item>
</array>

修改 由于上述问题现已解决 现在,我如何相应地将状态栏颜色更改为与背景相同的颜色

<!--status bar bg color-->
<color name="darkcolor1">#3b00e0</color>
<color name="darkcolor2">#e64705</color>
<color name="darkcolor3">#c80050</color>
<color name="darkcolor4">#bd00ae</color>
<color name="darkcolor5">#7300e0</color>
<color name="darkcolor6">#0c89db</color>
<color name="darkcolor7">#009d5c</color>
<color name="darkcolor8">#009d5c</color>
<color name="darkcolor9">#443cb6</color>
<color name="darkcolor10">#b6ae39</color>
<color name="darkcolor11">#ceac54</color>


<array name="statusBarBg">
    <item>@color/darkcolor1</item>
    <item>@color/darkcolor2</item>
    <item>@color/darkcolor3</item>
    <item>@color/darkcolor4</item>
    <item>@color/darkcolor5</item>
    <item>@color/darkcolor6</item>
    <item>@color/darkcolor7</item>
    <item>@color/darkcolor8</item>
    <item>@color/darkcolor9</item>
    <item>@color/darkcolor10</item>
    <item>@color/darkcolor11</item>
</array>

0 个答案:

没有答案