2015-07-21 68 views
2

任何人都可以指出爲什麼我的抽屜開關(用於打開導航抽屜的動畫的小漢堡圖標)拒絕切換我的顏色嗎?這給我造成了很多停機時間,我似乎無法弄清楚原因。更改Android上工具欄中DrawerToggle的顏色

這是我的主題 - 抽屜切換採用disabled_default_text的顏色。

<style name="Theme.MyApp.NoActionBar" parent="Theme.MyApp.NoActionBar"> 
    <item name="actionBarStyle">@style/Widget.MyApp.ActionBar</item> 
    <item name="colorAccent">@color/cs7</item> 
    <item name="colorControlNormal">@color/disabled_default_text</item> 
</style> 

而這裏的工具欄佈局:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@drawable/ab_solid" 
    android:minHeight="?attr/actionBarSize" 
    app:theme="@style/MyToolbarTheme" 
    app:elevation="@dimen/toolbar_elevation"/> 

MyToolbarTheme - 在我覆蓋colorControlNormal用白色。

<style name="MyToolbarTheme"  parent="@style/Widget.AppCompat.ActionBar.Solid"> 
    <item name="background">@drawable/ab_solid</item> 
    <item name="titleTextStyle">@style/MyTitleStyle</item> 
    <item name="colorControlNormal">@color/white</item> 
</style> 

有什麼奇怪的是,加入colorControlNormal改變從disabled_default_text顏色爲白色溢出菜單的顏色,但抽屜切換不會得到改變。任何人都可以弄清楚我做錯了什麼?

+0

什麼'Widget.MyApp.ActionBar'?如果您要創建[MCVE](http://stackoverflow.com/help/mcve),這將有所幫助。 – tachyonflux

回答

0

證明這一點:

style.xml

<style name="AppTheme" parent="AppTheme.Base"></style> 

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar"> 
    <item name="colorPrimary">@color/theme_primary</item> 
    <item name="colorPrimaryDark">@color/theme_dark</item> 
    <item name="colorAccent">@color/theme_accent</item> 
    <item name="android:windowBackground">@color/theme_wbackground</item> 
</style> 

風格v21.xml

<style name="AppTheme" parent="AppTheme.Base"> 
    <item name="android:colorPrimary">@color/theme_primary</item> 
    <item name="android:colorPrimaryDark">@color/theme_dark</item> 
    <item name="android:colorAccent">@color/theme_accent</item> 
    <item name="android:windowBackground">@color/theme_wbackground</item> 
    <item name="android:navigationBarColor">@color/theme_primary</item> 
</style> 

和INT工具欄: app_bar.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/theme_primary"/> 
4

你可以加drawerArrowStyle你的主題爲

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item> 
</style> 

,你可以定製你MyDrawerArrowToggle作爲

<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle"> 
     <item name="color">@color/white</item> 
</style> 
0

上述解決方案使用的風格,這可能會work.But如果你想與你的icon.Hope來代替它這個將有助於某人。

DrawerLayout mDrawerLayout = (DrawerLayout)findViewById(R.id.drawerLayout); 
Toolbar mToolbar = (Toolbar)findViewById(R.id.toolbar); 
ActionBarDrawerToggle mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, 
      R.string.navigation_drawer_open, R.string.navigation_drawer_close); 

mToggle.setDrawerIndicatorEnabled(false); // this is very important don't miss it 
mToggle.setHomeAsUpIndicator(R.drawable.ic_action_logo); // here your logo 

啓用抽屜指示你失去監聽切換,這就是爲什麼你必須自己來處理它的點擊。

mToggle.setToolbarNavigationClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View view) { 
       mDrawerLayout.openDrawer(GravityCompat.START) 
     } 
}); 

就是這樣快樂編碼:)

相關問題