Java - 如何更改应用程序选项卡的颜色?

时间:2018-03-28 18:43:51

标签: java android android-layout

如何更改标签标题背景的颜色?标准颜色为蓝色。如何将其更改为白色?就像这里:https://www.androidpolice.com/wp-content/uploads/2014/10/nexus2cee_43.png

1 个答案:

答案 0 :(得分:1)

自定义默认主题

例如,styles.xml文件应该类似于:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

知道颜色后,更新res / values / colors.xml中的值:

<?xml version="1.0" encoding="utf-8"?>
    <resources>
        <!--   color for the app bar and other primary UI elements -->
        <color name="colorPrimary">#3F51B5</color>

        <!--   a darker variant of the primary color, used for
               the status bar (on Android 5.0+) and contextual app bars -->
        <color name="colorPrimaryDark">#303F9F</color>

        <!--   a secondary color for controls like checkboxes and text fields -->
        <color name="colorAccent">#FF4081</color>
  </resources>

覆盖您想要的任何其他样式

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="android:windowBackground">@color/activityBackground</item>
</style>

引自:https://developer.android.com/guide/topics/ui/look-and-feel/themes.html#CustomizeTheme

编程方式:

您可以调用方法并在AndroidManifest.xml中设置主题。

<application
android:name=".Class.App"
android:icon="@mipmap/ic_test"
android:theme="@style/AppTheme" <-- Add your custom theme here
</application>