android - 自定义具有不同背景颜色的操作栏 - Android

标签 android android-layout android-fragments

我正在尝试为我的应用程序的 Actionbar 设置样式。因为我需要自定义更多,所以我用 ToolBar 替换了实际的 ActionBar。我想设计 ActionBar 如下图 image1 所示。

enter image description here

下面是我用来自定义的工具栏代码。

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,

enter image description here

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/

相关文章:

java - Android 发布应用程序市场自动执行购买后任务

带有图像的 Android ICS 选项菜单

Android:以编程方式更改时间的锁定/卡住布局?

android - 以选项卡形式返回 fragment 时崩溃。使用相同的 ID 查看

带有 fragment 和底部导航栏的 Android FloatingActionButton

java - 区分 Android 应用程序的调试和生产版本

java - Android Studio-ClassCastException 错误?

androidx 与 Spinner 和自定义对象的数据绑定(bind)

android - ScrollView 不调整大小

android - 在 Fragments onCreate 方法之前恢复 savedInstanceState