在Android Studio 1.4.1中设置Android工具栏背景和文本颜色 [英] Setting Android Toolbar Background and Text Colors in Android Studio 1.4.1

查看:91
本文介绍了在Android Studio 1.4.1中设置Android工具栏背景和文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to change activity action bar's background color and title color, i tried official tutorial and some answers from here but none worked for me , i'm missing something.

styles.xml

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" />

styles.xml(v21)

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>

MainActivity:

MainActivity :

<?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>

推荐答案

因此,如果像我一样,您正在使用Android Studio 1.4.1,并且对Android编程还是陌生的,则可以按照以下步骤设置标题和背景色:

So, if like me you are using Android Studio 1.4.1 and you are new to android programming, setting title and background colors can be done as follow :

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

Background:(check colors.xml with this generated code for BlanckActivity)

<?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>

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

Title,Subtitle and popup menu and its items (check "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>

我希望这可以帮助像我这样的人在正式的android教程提供的第一步中感到困惑.

I hope this can help someone who like me is confused in first steps provided with official android tutorials.

这篇关于在Android Studio 1.4.1中设置Android工具栏背景和文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆