在操作栏中更改溢出图标是否可能? 我的所有ActionBar项目都有蓝色图标,当溢出图标出现时,我也想更改它。
在操作栏中更改溢出图标是否可能? 我的所有ActionBar项目都有蓝色图标,当溢出图标出现时,我也想更改它。
你可以使用样式,但必须将其添加到主题声明中。
<resources>
<!-- Base application theme. -->
<style name="Your.Theme" parent="@android:style/Theme.Holo">
<!-- Pointer to Overflow style ***MUST*** go here or it will not work -->
<item name="android:actionOverflowButtonStyle">@style/OverFlow</item>
</style>
<!-- Styles -->
<style name="OverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_action_overflow</item>
</style>
</resources>
你也可以动态地更改它,我在这里详细介绍了如何操作:
parent="Widget.Sherlock.ActionButton.Overflow"
。 - Nick Whiteparent="@style/Widget.AppCompat.ActionButton.Overflow"
对我来说似乎有效。 - fattire如果您无法使其工作,请尝试去掉“android:”命名空间。
<item name="actionOverflowButtonStyle">@style/OverFlow</item>
Change your custom overflow icon of Actionbar in styles.xml.
<resources>
<!-- Base application theme. -->
<style name=“MyTheme" parent="@android:style/Theme.Holo">
<!-- Pointer to Overflow style DONT forget! -->
<item name="android:actionOverflowButtonStyle">@style/MyOverFlow</item>
</style>
<!-- Styles -->
<style name="MyOverFlow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_your_action_overflow</item>
</style>
</resources>
Put custom theme "MyTheme" in application tag of AndroidManifest.xml
<application
android:name="com.example.android.MainApp"
android:theme="@style/AppTheme">
</application>
玩得开心。@.@
styles.xml
中尝试做什么,都没有起作用。最终,如果你拥有AppCompat 23+,这是实际可行的最简单方法。toolbar.setOverflowIcon(drawable);
@adneal's answer 是正确的(因此这只是一个社区维基说明来扩展它)。
其中一条评论建议可能存在误解如何做到这一点,因此我的答案只是另一个关于如何覆盖溢出图标图像的示例。
下面的代码基于ADT示例新Android项目的模板样式。该代码来自res/values
文件夹中的styles.xml
文件。
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item>
</style>
<style name="OverflowMenuButton" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_menu_moreoverflow</item>
</style>
ic_menu_moreoverflow
的任何可绘制对象。如果您想快速测试它,请使用您的应用程序启动器图标文件名,这将使它的工作方式变得明显。ActionBar
样式时可以使用的有用资源是:
在那里,您可以定义特定的颜色来使用您的溢出图标,并且ZIP文件将为您包括正确的styles.xml
文件。在长时间的搜索之后,我得到了以下应遵循的指导:
在theme.xml中的主题中添加项目:
<item name="android:actionBarWidgetTheme">@style/widgetStyle</item>
<item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
在同一文件中的样式中添加图标,我的意思是theme.xml:
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/icon_menu</item>
</style>
查看要更改的自定义图标
它对我有效
。
toolbar.setOverflowicon(getDrawable(R.id.whiteIcon));
或者
toolbar.setOverflowicon(getDrawable(R.id.redIcon));