【问题标题】:padding to ActionBarDrawerToggle填充到 ActionBarDrawerToggle
【发布时间】:2017-04-19 22:56:47
【问题描述】:

我想将 ActionBarDrawerToggle 图标(汉堡)保持在屏幕边缘。

但默认情况下,它会在边缘留出一些空间。

如何将图标保持在边缘(基本上没有空格)。

【问题讨论】:

  • 你试过设置填充吗?
  • 老实说,如果你这样做,那看起来会很丑。但是,如果您真的想要,则可以获得对 ImageButton 的引用。然后,您可以更改其左侧填充、x 坐标等。或者,您可以在 Toolbar 中创建自己的切换,然后根据需要进行设置。
  • 嗨,迈克,是的,我知道它可能看起来很难看,但这是要求。是否可以获得 ActionBarDrawerToggle 图标资源的参考?

标签: android navigation-drawer drawerlayout actionbardrawertoggle


【解决方案1】:

可能为时已晚,但是...

其实迈克已经在这里回答了类似的问题Get reference to drawer toggle in support actionbar

我只是重用了他的代码。添加 ActionBarDrawerToggle 并在其上调用 syncState() 后

final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(...);

//Setting the actionbarToggle to drawer layout
drawerLayout.setDrawerListener(actionBarDrawerToggle);

//calling sync state is necessay or else your hamburger icon wont show up
actionBarDrawerToggle.syncState();

您可以遍历工具栏的子项,然后...

for (int i = 0; i < toolbar.getChildCount(); i++) {
    if(toolbar.getChildAt(i) instanceof ImageButton) {
        ImageButton imageButton = (ImageButton) toolbar.getChildAt(i);
        imageButton.setPadding(50, 100, 50, 50);
    }
}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2015-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多