用于预棒棒糖设备的android工具栏

时间:2014-11-04 18:56:24

标签: android toolbar

当我从ActionBar更改为工具栏时遇到了很多问题。我在这里列出了

1 )我有许多使用backstack添加/替换的片段。当我按下后退按钮但当我改为工具栏时,当我按下后退按钮时,应用程序关闭。

2 )弹出菜单背景为黑色。

<item name="android:popupMenuStyle">@style/PopupMenu</item>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@android:color/white</item>
</style>

即使这样也没有用。

如果我使用AppCompat.Light主题,popupmenu的背景颜色为白色,但随后NavigationIndicator图标和所有变为黑色的

3 )这是我的菜单风格。这里没有显示id为“add”的项目,而是像往常一样使用了showAsAction。它在菜单中(当我按下3个垂直点按钮时,菜单会膨胀),但图标不可见。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".com.hirak.assistere_doit.do_it_main_screen">

<item android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="Settings" />
<item android:id="@+id/add"
    android:icon="@drawable/add"
    android:showAsAction="always"/>

</menu>

2 个答案:

答案 0 :(得分:6)

要设置弹出菜单的样式,您需要应用弹出窗口

<android.support.v7.widget.Toolbar android:id="@+id/toolbar" app:theme="@style/ActionBar" android:layout_width="match_parent" android:layout_height="wrap_content" app:popupTheme="@style/ToolbarPopup" />

然后在您的主题中,覆盖您想要更改的值

<style name="ToolbarPopup" parent="Widget.AppCompat.Light.PopupMenu">
    <item name="android:background">@color/white</item>
    <item name="android:textSize">14sp</item>
</style>

将导航指示器更改为白色,添加到工具栏

<style name="ActionBar" parent="Widget.AppCompat.Toolbar">
    ...
    <item name="android:textColorSecondary">@color/white</item>
    <item name="actionMenuTextColor">@color/white</item>
    <item name="android:textColorPrimary">@color/white</item>
</style>

至于后退按钮问题,我需要更多信息 - 代码等。

答案 1 :(得分:0)

关于后退按钮问题 当我改为工具栏时,我遇到了同样的问题 问题在于使用 FragmentManager instead of support.v4.app.FragmentManager Creating FragmentManager object by getSupportFragmentManager()方法并将所有片段导入到android.support.v4.app.Fragment - 为我解决了这个问题。

相关问题