我试图将操作栏的背景颜色更改为另一种颜色,而不是默认颜色。我在用 :
implementation 'com.google.android.material:material:1.2.0-alpha05'
...值/样式.xml:
<resources>
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorPrimaryVariant">@color/primaryLightColor</item>
<item name="colorOnPrimary">@color/primaryTextColor</item>
<item name="colorSecondary">@color/secondaryColor</item>
<item name="colorSecondaryVariant">@color/secondaryDarkColor</item>
<item name="colorOnSecondary">@color/secondaryTextColor</item>
<item name="android:windowBackground">@color/activityBackground</item>
</style>
</resources>
...和:夜/colors.xml
<color name="primaryDarkColor">#430F58</color>
<color name="primaryColor">#F7F2F8</color>
<color name="secondaryColor">#9e9e9e</color>
<color name="secondaryDarkColor">#707070</color>
<color name="primaryTextColor">#eceff1</color>
<color name="activityBackground">#121212</color>
...mainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}[enter image description here][1]
}
我的效果很好,但我的操作栏的颜色一直保持黑色。
你能帮助我吗 ?谢谢