【问题标题】:Decreasing space taken by navigation drawer icon减少导航抽屉图标占用的空间
【发布时间】:2015-05-05 16:08:17
【问题描述】:

我的操作栏有导航抽屉和个人资料图像图标。我想减少导航抽屉图标和个人资料图像图标之间的空间,但导航抽屉图标占用固定空间,即使我用小图标替换它。

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

    public void onDrawerClosed(View view) {

        super.onDrawerClosed(view);

        invalidateOptionsMenu();
    }

    public void onDrawerOpened(View drawerView) {

        super.onDrawerOpened(drawerView);

        invalidateOptionsMenu();
    }
};
ActionBar mActionBar = getSupportActionBar();
View mCustomView = mInflater.inflate(R.layout.actionbar_home, null);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayHomeAsUpEnabled(true);
mActionBar.setHomeButtonEnabled(true);
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);

actionbar_home.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/tabbackground"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/profileImageActionBar"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_centerVertical="true"
        android:visibility="visible"
        app:border_width="1dp"
        app:border_color="#FFFFFF"
        android:layout_alignParentLeft="true" />

    <TextView
        android:id="@+id/actionbar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:maxLines="1"
        android:singleLine="true"
        android:text="Home"
        android:layout_toRightOf="@+id/profileImageActionBar"
        android:layout_marginLeft="50dp"
        android:textColor="@color/white"
        android:textSize="22sp"/>

</RelativeLayout>

【问题讨论】:

  • 请查看我对类似问题的回答stackoverflow.com/questions/28582747/…
  • @AB 导航抽屉图标不是我的自定义 xml 的一部分
  • 尝试减少头像中的剩余空间..
  • R.drawable.ic_drawer 是导航抽屉图标

标签: android android-actionbar navigation-drawer


【解决方案1】:

您能否添加一个屏幕截图来说明您的外观?

我尝试使用一个简单的ActionBar mActionBar = getActionBar() 和像你这样的自定义视图,并隐藏像这样的图标mActionBar.setIcon(android.R.color.transparent),并且导航抽屉图标和自定义视图之间的空间非常好。

【讨论】:

  • 我在mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { 中添加导航抽屉图标,其中R.drawable.ic_drawer 是导航抽屉图标
  • 如果我将marginLeftprofileImageActionBar 设置为负数,则导航抽屉图标会出现在图像顶部
  • 是的,我知道 R.drawable.ic_drawer 是导航抽屉图标,但对我来说,不使用 supportActionBar,我必须将操作栏图标设置为透明以便隐藏它。但是设置负数是可以的,但是不要把空间缩小太多,以免重叠。
猜你喜欢
  • 2016-11-25
  • 1970-01-01
  • 1970-01-01
  • 2020-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多