android ToolBar 设置颜色

2018-10-30 00:16:41


通常情况加我们需要与toolbar标题统一的颜色,比如白色,那么需要在布局文件中的toolbar空间中再添加两行样式代码即可:

<android.support.v7.widget.Toolbar
        android:id="@+id/main_toolbar"
        style="@style/Toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:minHeight="?attr/actionBarSize"
        app:contentInsetStart="0dp"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        >

app:popupTheme——有时候我们有需求:ActionBar文字是白的,ActionBar Overflow弹出的是白底黑字让ActionBar文字是白的,那么对应的theme肯定是Dark。可是让ActionBar弹出的是白底黑字,那么需要Light主题。这时候popupTheme就派上用场了。android:theme 与app:theme——在AppCompat v21里,提供了一个快速方便的方法设置Toolbar的主题,使用app:theme。而新版本22.1.x中,AppCompat 允许对 Toolbar 使用 android:theme代替 app:theme。最好的一点是:它会自动继承父视图的theme ,并且兼容所有APIv11以上的设备。


例如下面


 <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
 
        <View
            android:layout_width="match_parent"
            android:layout_height="24dp"/>
 
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#ffF5F5F5"
            app:layout_scrollFlags="scroll"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:theme="@style/AppTheme.PopupOverlay">
 
            <TextView
                android:id="@+id/toolbar_edit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:singleLine="true"
                android:text="编辑"
                android:textColor="@color/left_title"
                android:textSize="18sp" />
 
 
        <TextView
            android:id="@+id/toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:singleLine="true"
            android:text="自选"
            android:textColor="@color/background_title"
            android:textSize="20sp" />
 
        </android.support.v7.widget.Toolbar>
 
    </android.support.design.widget.AppBarLayout>

自定义主题文件如下


 <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
        <!-- 设置Menu菜单的背景色 -->
        <item name="android:itemBackground">@color/left_title</item>
        <!-- 设置Menu菜单的字体颜色 -->
        <item name="android:textColorPrimary">@color/left_title</item>
        <item name="colorControlNormal">@color/left_title</item><!-- 主要是这个起作用,修改默认返回键的颜色-->
        <!-- 设置Menu窗口不覆盖Toolbar视图 -->
        <item name="overlapAnchor">false</item>
    </style>


  • 2019-01-01 21:42:34

    php-fpm 启动参数及重要配置详解

    如果file_get_contents请求的远程资源如果反应过慢,file_get_contents就会一直卡在那里不会超时。我们知道php.ini 里面max_execution_time 可以设置 PHP 脚本的最大执行时间,但是,在 php-cgi(php-fpm) 中,该参数不会起效。真正能够控制 PHP 脚本最大执行时间的是 php-fpm.conf 配置文件中的request_terminate_timeout参数。

  • 2019-01-08 14:35:50

    ueditor 特殊符号转义

    几个月前,就有同事跟我反馈,说磨途歌的留言板有问题。当时看了一下,她用的是谷歌浏览器,确实打不出中文,才按下一个字母,英文字母就从输入法的输入框中直接跳出来了,更换火狐浏览器就没这个问题。很奇怪的是,在我电脑上的火狐浏览器跟谷歌浏览器都没有问题,一开始还以为是她电脑的问题,就没在意了。