简体   繁体   English

Android:如何向操作栏中的导航抽屉图标添加填充

[英]Android: How to add padding to navigation drawer icon in the action bar

I am still struggling with finding a way to add padding/margin space between the navigation drawer icon in the action bar and the screen (top left of screen). 我仍在努力寻找一种在操作栏中的导航抽屉图标和屏幕(屏幕左上方)之间添加填充/边距空间的方法。 Thanks in advance and I am trying to find any solution so either java or xml is perfect. 在此先感谢,我正尝试找到任何解决方案,因此java或xml都是完美的。

Regards, 问候,

Ryan 瑞安

For padding, you can use: 对于填充,您可以使用:

ImageView view = (ImageView)findViewById(android.R.id.home);
view.setPadding(left, top, right, bottom);

There is a tweak, 有一个调整,

What you can do is that you can put the Navigation drawer icon to transparent and instead of application icon set the drawer icon.In that way the drawer icon will be moved away from left side of your screen. 您可以做的是将导航抽屉图标置于透明状态,而不是将应用程序图标设置为抽屉图标,这样抽屉图标将从屏幕左侧移开。

ActionBar bar;
bar = getActionBar();
bar.setIcon(getResources().getDrawable(R.drawable.ic_drawer));//where R.drawable.ic_drawer is your drawer icon

ActionBarDrawerToggle mDrawerToggle;
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_drawer_transparent, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    )

I hope this helps you in some way. 希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM