如何更改在ActionBar汉堡包图标的颜色? [英] How do I change the color of the ActionBar hamburger icon?

查看:668
本文介绍了如何更改在ActionBar汉堡包图标的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NavigationView从Android设计支持库和工具栏,一切工作正常,但我想知道如何使汉堡包图标暗(现在它呈现白色)。此外,我想调整动作条标题从屏幕边缘的距离。所以我怎么做呢?感谢您的帮助。

I'm using NavigationView from android design support library and toolbar and everything works fine, but I want to know how to make the hamburger icon dark (right now it appears white). Also I wanna adjust distance from screen edge to ActionBar Title. So how do I do this? Thanks for help.

我将主题定为Theme.AppCompat.Light.NoActionBar。所以我使用的工具栏。这里是我的code:

I set theme as Theme.AppCompat.Light.NoActionBar. So I use toolbar. Here is my code:

public class MainActivity extends AppCompatActivity {

//Defining Variables
private Toolbar toolbar;
private NavigationView navigationView;
private DrawerLayout drawerLayout;
ViewPager pager;
ViewPagerAdapter adapter;
SlidingTabLayout tabs;
CharSequence Titles[]={"Песни","Исполнители"};
int Numboftabs =2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initializing Toolbar and setting it as the actionbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

和XML:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context=".MainActivity">

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    >
    <include
        android:id="@+id/toolbar"
        layout="@layout/tool_bar"
        />

    <ru.amdm.amdm.SlidingTabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="2dp"
        android:background="@color/ColorPrimary"/>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:foreground="?android:windowContentOverlay">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"

            android:layout_height="match_parent"
            android:layout_width="match_parent"/>
    </FrameLayout>

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    app:headerLayout="@layout/header"
    app:menu="@menu/drawer"
    />

推荐答案

要改变汉堡图标,只需创建一个新的图标(例如ic_my_dark_menu)然后分配,为了你的动作吧:

To change the hamburger icon, just create a new icon (e.g. ic_my_dark_menu) then assign that to your action bar:

actionBar.setHomeAsUpIndicator(R.drawable.ic_my_dark_menu);

或者,您可以色调现有的图标,如果你宁愿做这种方式:

Or, you can tint your existing icon, if you'd rather do it this way:

Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu, null);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.BLACK);
actionBar.setHomeAsUpIndicator(drawable);

要改变的空间量你的动作条的标题和边缘之间,只需编辑您的工具栏布局(RES /布局/ tool_bar.xml)。例如,您可以添加填充是这样的:

To change amount of space between your action bar title and the edge, just edit your toolbar layout (res/layout/tool_bar.xml). For example, you can add padding like this:

RES /布局/ tool_bar.xlml

res/layout/tool_bar.xlml

<android.support.v7.widget.Toolbar
    ...
    android:paddingTop="16dp" />

这篇关于如何更改在ActionBar汉堡包图标的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆