Android开发显示头部Bar
需求:
显示如下图:

显示头部Bar,颜色也能自定义。
解决方案
这个修改是在如下三个文件里进行修改:


按顺序修改:
themes.xml(night):
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.CropIrrigation" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your dark theme here. -->
         <item name="colorPrimary">@color/my_dark_primary</item>
    </style>
</resources>
themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Base.Theme.CropIrrigation" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your light theme here. -->
        <!-- <item name="colorPrimary">@color/my_light_primary</item> -->
        <!-- Customize your light theme here. -->
        <item name="colorPrimary">@color/myBarColor</item>.
        <item name="titleTextColor">@color/myBarColor</item>
    </style>
    <style name="Theme.CropIrrigation" parent="Base.Theme.CropIrrigation" />
</resources>
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="myBarColor">#673AB7</color>
    <color name="my_dark_primary">#673AB7</color>
    <color name="titleColor">#E3D9D9</color>
    <color name="colorPrimary">#03A9F4</color>
</resources>
在主题文件**themes.xml:中,起作用的就是 Theme.MaterialComponents.Light.DarkActionBar,在属性文件colors.xml:**中起作用的就是 <color name="colorPrimary">#03A9F4</color>,<color name="my_dark_primary">#673AB7</color>




![2023年中国冲击波治疗仪市场发展趋势分析:未来市场增长空间更大[图]](https://img-blog.csdnimg.cn/img_convert/336a737b22129604e4a4cbe730e5a780.png)






![2023年中国脑电仿生电刺激仪发展趋势分析:智能化、精准化、使用感不断提高[图]](https://img-blog.csdnimg.cn/img_convert/d8015bcacf76a353415cbc5daff29a98.png)







