首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android.support.v7工具栏和绘图布局-如何隐藏汉堡包图标

android.support.v7工具栏和绘图布局-如何隐藏汉堡包图标
EN

Stack Overflow用户
提问于 2015-02-19 18:08:12
回答 3查看 6.4K关注 0票数 6

我正在实现工具栏和导航抽屉。我使用自己的视图自定义我的工具栏。我在我的工具栏中有自己的菜单(汉堡)图标来打开导航抽屉,并且我在菜单图标(汉堡).So上显示徽章计数。我想隐藏默认的汉堡图标。

我试过这样做:

代码语言:javascript
复制
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(false);

请提前帮助me.Thanks。

EN

回答 3

Stack Overflow用户

发布于 2015-03-25 23:47:25

在ActionBarDrawerToggle上调用.setDrawerIndicatorEnabled(false);

票数 18
EN

Stack Overflow用户

发布于 2016-03-01 11:45:19

这对我来说很有效:

代码语言:javascript
复制
public void setLogo(String imageUrl) {
  ViewGroup toolbarView = (ViewGroup) toolbar.findViewById(R.id.toolbar);

  // set an arbitrary logo so the support library adds an ImageView to the toolbar.
  // without this, there would be no ImageView elements in the toolbar
  // and the following loop would not work
  // `empty_drawable` is a simple rectangle of size 100x100 with a bg color
  // matching that of the toolbar
  // the size really matters because the smaller you set this image, the next logo
  // you set will be of that size. If your arbitrary drawable is of size 1x1, then
  // the next logo you set will be of the same size. At least that is what happens
  // for me when I load an image with Glide.
  // Your drawable should have a background color too. I chose the toolbar's
  // background color. If you don't set a background color, your app would crash on Kitkat.
  toolbar.setLogo(R.drawable.empty_drawable);

  for (int i = 0; i < toolbarView.getChildCount(); i++) {
    if ((toolbarView.getChildAt(i) instanceof ImageView)) {
      ImageView logoView = (ImageView) toolbarView.getChildAt(i);

      if (!TextUtils.isEmpty(imageUrl)) {
        // this way I can download an image and set the logo that way
        Glide.with(MainActivity.this).load(imageUrl).into(logoView);

        // I do this because there is no space between logo and the toolbar title
        logoView.setPadding(0, 0, 30, 0);

        // and this is because of the `else` block
        logoView.setVisibility(View.VISIBLE);
      } else {
        // pass null to `setLogo()` to hide the logo
        logoView.setVisibility(View.GONE);
        logoView.setPadding(0, 0, 0, 0);
      }
      break;
    }
  }
}

这是我的工具栏:

代码语言:javascript
复制
<android.support.v7.widget.Toolbar
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="?attr/actionBarSize"
  android:animateLayoutChanges="true"
  app:popupTheme="@style/AppTheme.PopupOverlay"
  app:title="@string/app_name"
  tools:ignore="UnusedAttribute" />

android:animateLayoutChanges="true"部分让这一切变得非常美好。tools:ignore="UnusedAttribute"是因为我的应用程序的最低SDK设置为9。

票数 1
EN

Stack Overflow用户

发布于 2015-02-19 19:32:36

在您的活动的onCreate中尝试以下内容:

代码语言:javascript
复制
getActionBar().setIcon(
   new ColorDrawable(getResources().getColor(android.R.color.transparent)));

如果您正在使用AppCompat,请将getActionBar替换为getSupportActionBar

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28603549

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档