0

我一個出現在鏈接都試過了一個像如何更改新材質主題中的工具欄主圖標(後退箭頭)顏色?

How to change color of the back arrow in the new material theme?

How to change Toolbar home icon color

Change toolbar back arrow color

How to change change text and arrow color on Toolbar?

Android: unable to change color of back arrow navigation icon

等,

但沒有什麼適合我的。

我的佈局XML代碼,

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     style="@style/MyCustomTabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:background="?attr/colorPrimary" 
     android:elevation="6dp" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     style="@style/MyCustomTabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:minHeight="?attr/actionBarSize" 
     app:tabMaxWidth="0dp" /> 
在styles.xml

<style name="MyCustomTabLayout" parent="Theme.AppCompat.Light"> 
    <item name="tabIndicatorHeight">2dp</item> 
    <item name="tabPaddingStart">12dp</item> 
    <item name="android:layout_width">match_parent</item> 
    <item name="tabPaddingEnd">12dp</item> 
    <item name="tabBackground">@drawable/background_tab_item</item> 
    <item name="tabIndicatorColor">@color/jd_yellow</item> 
    <item name="android:layout_gravity">center</item> 
    <item name="android:gravity">center</item> 
    <item name="tabSelectedTextColor">@color/jd_white</item> 
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item> 
    <item name="android:textAppearance">@style/MyCustomTabTextAppearance</item> 
    <item name="android:background">@drawable/background_tab_item</item> 
    <item name="android:textColorSecondary">@color/jd_white</item> 
    <item name="colorControlNormal">@color/jd_white</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
    <item name="actionBarTheme">@style/MyApp.ActionBarTheme</item> 
    <item name="actionBarWidgetTheme">@style/WidgetStyle</item> 
    <item name="colorPrimary">@color/jd_white</item> 
    <item name="colorPrimaryDark">@color/jd_white</item> 
    <item name="android:textColorPrimary">@color/jd_white</item> 
</style> 

<style name="WidgetStyle" parent="style/ThemeOverlay.AppCompat.Light"> 
    <item name="colorControlNormal">@color/jd_white</item> 
</style> 

<style name="MyApp.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar"> 
    <!-- change color the arrow or three lines --> 
    <item name="colorControlNormal">@color/jd_white</item> 
</style> 

<!-- Style for the navigation drawer icon --> 
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@color/jd_white</item> 
</style> 

<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab"> 
    <item name="android:textColor">@color/jd_white</item> 
    <item name="android:textSize">@dimen/tab_layout_text_size</item> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">match_parent</item> 
    <item name="android:layout_gravity">center</item> 
    <item name="android:gravity">center</item> 
</style> 

也嘗試添加下面的onCreate()

Drawable upArrow = ContextCompat.getDrawable(mContext, R.drawable.abc_ic_ab_back_material); 
     upArrow.setColorFilter(ContextCompat.getColor(mContext, R.color.white), PorterDuff.Mode.SRC_ATOP); 
     getSupportActionBar().setHomeAsUpIndicator(upArrow); 

沒有工作,還是它的顏色是黑色, 我在做什麼錯?請幫忙。

回答

0

您可以製作自己喜歡的顏色,然後將其放置在工具欄上。

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     getSupportActionBar().setHomeAsUpIndicator(R.drawable.YOUR_ASSET); 
+0

但如果抽屜打開會出現什麼情況?默認情況下,當打開抽屜時(也用動畫),三行圖像會變成黑色箭頭,我可以用這種方法實現嗎? –

0

嘗試使用這種風格爲您的安卓主題工具欄:

<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.Dark"> 
    <item name="android:textColorSecondary">@color/jd_white</item> 
</style> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    style="@style/MyCustomTabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:background="?attr/colorPrimary" 
    android:elevation="6dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/ToolbarStyle" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
+0

謝謝,但這也不適用於我的情況 –

0

無數的黑客和怪誕的情況後,該作品般的魅力

<style name="App"/> 
<style name="App.Toolbar"> 
    <item name="android:id">@id/toolbar</item> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">?attr/actionBarSize</item> 
    <item name="android:background">@android:color/white</item> 
    <item name="android:minHeight">?attr/actionBarSize</item> 
    <item name="android:theme">@style/ThemeOverlay.AppCompat.Light</item> 
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Dark</item> 
</style> 
<style name="App.Toolbar.Transparent"> 
    <item name="android:background">@android:color/transparent</item> 
</style> 
相關問題