2015-01-17 58 views
12

使用AppCompat工具欄,我希望能夠更改ActionMode更改時溢出菜單圖標的顏色。AppCompat工具欄:更改ActionMode中的溢出圖標顏色

例如,在正常工具欄模式下,溢出圖標將變爲白色。並且會在ActionMode上變黑。到目前爲止,我設法改變了動作模式的背景以及標題文本。但我還沒有找到一種方法來改變溢出菜單圖標的顏色。

我知道有可用的答案: Change ActionMode Overflow icon

我嘗試的第一個解決方案,我無法找到的菜單圖標。

第二種解決方案,即使延遲50L,也會導致溢出菜單圖標閃爍動作模式的預期顏色,造成很大的震動。

回答

40

以下行添加到你的主題屬性:

<item name="android:textColorSecondary">@android:color/white</item> 
+0

我不知道我也有第二個解決方案,請檢查此鏈接http://stackoverflow.com/questions/26671677/android-appcompat-21-how-to-change-the-back-icon-and-the-overflow -icon-to-a -c/33938229#33938229 – Piyush

+3

請注意,這也會更改底部菜單中的文本顏色(通過按特殊鍵顯示)。如果'textColorSecondary'和菜單背景被設置爲相同(或相似)的顏色,這可能是一個問題。 – Storix

+2

貝特的方法將是由它創建一個單獨的樣式: '<樣式名稱=「ToolbarTheme」父=「AppTheme.MyTheme」> <項名稱=「機器人:textColorSecondary」> @機器人:顏色/白色 ' – Ariq

4

鑑於以下工具欄:

<android.support.v7.widget.Toolbar 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?attr/actionBarSize" 
    theme="@style/MyToolbarStyle" /> 

定義風格,無論從ThemeOverlay.AppCompat.ActionBarDark變種繼承。您可以通過設置textColorPrimary屬性來更改溢出圖標的顏色。如果你有興趣改變ActionBarDrawerToggle的顏色,那麼你也可以設置colorControlNormal

<style name="MyToolbarStyle" parent="ThemeOverlay.AppCompat.ActionBar"> 
    <item name="colorControlNormal">#333333</item> 
    <item name="android:textColorPrimary">#333333</item> 
</style> 

您可以用同樣的方法更改的工具欄風格爲你的問題聯繫在一起,即getSupportActionBar().getThemedContext().getTheme().applyStyle

+1

嗨。感謝您的回答......但問題在於溢出圖標菜單顏色由ActionMode的溢出圖標和工具欄的溢出圖標共享。目標是爲兩者都有不同的顏色。 – Jun

3
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
    <item name="android:actionOverflowButtonStyle">@style/ActionButton.Overflow.Icon</item> 
</style> 

<style name="ActionButton.Overflow.Icon" parent="android:style/Widget.Holo.Light.ActionButton.Overflow"> 
    <item name="android:src">@mipmap/yourwanticon</item> 
</style> 
1

要正確更改工具欄的溢出菜單圖標的顏色,請將工具欄的主題設置爲AppCompat dark ActionBar主題。例如:

在你RES /價值/ style.xml文件創建從程序兼容性繼承了這種方式一個主題:

<style name="AppTheme.MyThemeName" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

現在設置工具欄的主題,這個主題:

<android.support.v7.widget.Toolbar 
    android:id="+id/my_toolbar_id 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/my_toolbar_height" 
    android:theme="@style/AppTheme.MyThemeName"> 

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

y中添加該代碼在你的水庫 - > styles.xml

<style name="ToolbarColored" parent="AppTheme"> 
<item name="android:textColorSecondary">YOUR_COLOR</item> 
</style> 

那麼你的 'ToolbarColored' 風格我們喜歡belove

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     app:theme="@style/ToolbarColored" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 
0

首先XCML文件讓你自定義樣式

<style name="ToolbarColoredBackArrow" parent="AppTheme"> 
    <item name="android:textColorSecondary">@color/white</item> 
</style> 

然後,只需將其添加到您的工具欄

 <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:titleTextColor="@color/white" 
      app:theme="@style/ToolbarColoredBackArrow" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_scrollFlags="scroll|enterAlways" 
      android:background="?attr/colorPrimary" /> 
相關問題