簡體   English   中英

導航抽屜圖標更改顏色

[英]Navigation drawer icon change color

我想將導航抽屜圖標(3 個垂直條)的顏色從白色更改為灰色。 我如何以最簡單的方式做到這一點?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Toolbar Title"
    android:id="@+id/toolbar_title"
    android:textColor="#010101" />
<!--android:layout_gravity="center"-->



</android.support.v7.widget.Toolbar>

您可以使用如下方式以編程方式更改圖標本身:

toolbar.setNavigationIcon(R.drawable.new_icon);

獲取可繪制對象

Drawable icMenu = ContextCompat.getDrawable(this, R.drawable.ic_hamburguer);

給可繪制對象着色

icMenu.setColorFilter(getResources().getColor(android.R.color.darker_gray), PorterDuff.Mode.SRC_ATOP);

與 actionBar 一起使用

actionBar.setHomeAsUpIndicator(icMenu);

actionBar.setDisplayHomeAsUpEnabled(true);

或者工具欄

工具欄.setNavigationIcon(icMenu);

更改工具欄的主題

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey"
local:theme="@style/CustomTheme"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Toolbar Title"
    android:id="@+id/toolbar_title"
    android:textColor="#010101" />
<!--android:layout_gravity="center"-->



</android.support.v7.widget.Toolbar>

在你的styles.xml

像這樣創造新的風格。

<style name="CustomTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">#COLOR_CODE_FOR_YOUR_TEXT</item>
    <item name="android:textColorSecondary">#COLOR_CODE_FOR_YOUR_TOOLBAR_ICON</item>
</style>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM