工具栏按钮重力扩展工具栏 [英] Toolbar button gravity for extended toolbar

查看:282
本文介绍了工具栏按钮重力扩展工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去把我背的导航图标的位置在我的扩展工具栏,如下所示:

Im trying to set the position of my back navigation icon in my extended toolbar as follows:

<android.support.v7.widget.Toolbar  xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    app:theme="@style/Toolbar"
    android:minHeight="@dimen/action_bar_height"
    app:buttonGravity="top"
    android:gravity="top"
    android:background="?attr/colorPrimary" />

检查工具栏的来源,我们可以看到以下内容:

Checking the sources of toolbar we can see the following:

private void ensureNavButtonView() {
    if (mNavButtonView == null) {
        mNavButtonView = new ImageButton(getContext(), null,
            R.attr.toolbarNavigationButtonStyle);
        final LayoutParams lp = generateDefaultLayoutParams();
        lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK);
        mNavButtonView.setLayoutParams(lp);
    }
}

其中, mButtonGravity 通过

mButtonGravity = a.getInteger(R.styleable.Toolbar_buttonGravity, Gravity.TOP);

所以,正确读这篇文章,我的工具栏的重心应该已经是 Gravity.TOP 如果不配置。然而,它看起来是这样的:

So reading this correctly, the gravity of my toolbar should already be Gravity.TOP if nothing is configured. However it looks like this:

推荐答案

我打了一下周围,并测试了几个的组合,可以说按钮的重力和安卓了minHeight 不想成为朋友。

I played around a bit and tested a couple of combinations and can say that button's gravity and android:minHeight don't want to be friends.

这应该工作的罚款:

<android.support.v7.widget.Toolbar  xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_height="@dimen/action_bar_height"
    android:layout_width="match_parent"
    app:theme="@style/Toolbar"
    android:minHeight="?attr/actionBarSize"
    android:gravity="top"
    android:background="?attr/colorPrimary" />

这篇关于工具栏按钮重力扩展工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆