【发布时间】: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