我正在尝试为我的应用程序的 Actionbar 设置样式。因为我需要自定义更多,所以我用 ToolBar 替换了实际的 ActionBar。我想设计 ActionBar 如下图 image1 所示。
下面是我用来自定义的工具栏代码。
custom_actionbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent" >
<android.support.v7.widget.Toolbar
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</RelativeLayout
activity_toolbar.java
// Custom actionbar starts here
Toolbar action = (Toolbar) findViewById(R.id.actionbar);
action.inflateMenu(R.menu.menu_scrollable_tabs);
action.setNavigationIcon(R.drawable.ct_drawer);
我得到如下所示的操作栏 image2,
1) 我面临的问题是我没有获得与客户要求相同的导航图标和菜单图标。
2) 如何使用工具栏实现这一点。请提供是否有任何其他替代方法可以在 android 中实现此目的。
请帮忙。
最佳答案
在 styles.xml 中为您的样式设置主题的 colorPrimary 值
<item name="colorPrimary">@color/colorPrimary</item>
然后在 colors.xml 文件中定义你的颜色,如下所示
<color name="colorPrimary">#3F51B5</color>
请看这个设置原色的例子 http://www.dilan.me/articles/tech-notes/android-tips-2-how-to-change-the-main-colors-of-your-app/
关于android - 自定义具有不同背景颜色的操作栏 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33213439/