相关疑难解决方法(0)

如何居中工具栏后退按钮?

我在尝试将支持工具栏上的后退按钮居中时遇到问题.我在ActionBarActivity中使用它.

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:toolbar="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    toolbar:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    toolbar:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
Run Code Online (Sandbox Code Playgroud)

并在Activity中设置向上导航,onCreate()如下所示:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

getSupportActionBar().setTitle(R.string.title_activity_scanner);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)

但是,我得到的是: 没有居中的后退按钮截图 如您所见,后退按钮放错了位置

编辑:问题似乎在于?attr/actionBarSize设置为40dp 的自定义值,但是,现在结果证明,它是错误放置的标题.

android android-actionbaractivity material-design android-toolbar

33
推荐指数
2
解决办法
1万
查看次数