在Android Studio 1.4.1中设置Android工具栏背景和文本颜色

Ana*_*nas 14 android android-studio android-styles

我正在尝试更改活动操作栏的背景颜色和标题颜色,我尝试了官方教程和一些答案,但没有一个对我有用,我错过了一些东西.

styles.xml

<!-- Base application theme. -->
<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>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Run Code Online (Sandbox Code Playgroud)

styles.xml(v21)

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

主要活动 :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    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:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

Ana*_*nas 44

所以,如果像我一样你使用Android Studio 1.4.1并且你是Android编程新手,可以按如下方式设置标题和背景颜色:

背景:(使用生成的BlanckActivity代码检查colors.xml)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color><!--Background color for AppBar-->
    <color name="colorPrimaryDark">#303F9F</color><!--i ignore its use-->
    <color name="colorAccent">#FF4081</color><!--color effects, EditText, RadioButtons...-->
</resources>
Run Code Online (Sandbox Code Playgroud)

标题,字幕和弹出菜单及其项目(选中"styles.xml"):

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="android:textColorPrimary">TITLE_COLOR_GOES_HERE</item>
        <item name="android:textColorSecondary">SUBTITLE_COLOR_GOES_HERE</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:colorBackground">MENU_POPUP_BACK_COLOR</item>
        <item name="android:textColor">@color/MENU_POPUP_ITEMS_COLOR</item>
</style>
Run Code Online (Sandbox Code Playgroud)

活动的主要颜色

我希望这可以帮助喜欢我的人在官方安卓教程提供的第一步中感到困惑.