我在尝试将支持工具栏上的后退按钮居中时遇到问题。 我在 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" />
并在 Activity 的 onCreate()
中设置向上导航,如下所示:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.title_activity_scanner);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
但是,我得到的是:
如您所见,后退按钮放错了位置
编辑:
问题似乎在于 ?attr/actionBarSize
的自定义值设置为 40dp,然而,现在事实证明,它是放错位置的标题。
最佳答案
Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements:
A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.
因此,如果您将 minHeight 属性设置为与工具栏高度(layout_height )相同,则后退箭头将垂直居中。
关于android - 如何使工具栏后退按钮居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29890861/