Android 从AppCompat工具栏继承更改工具栏图标边距

Android 从AppCompat工具栏继承更改工具栏图标边距,android,android-toolbar,Android,Android Toolbar,在我的项目中,我正在扩展android.support.v7.widget.Toolbar来为类添加一些额外的功能。但是,当我在布局文件中实现此类时,它会更改工具栏上显示的图标的边距(或填充,不确定…) 默认android.support.v7.widget.Toolbar结果: 自定义工具栏类结果: 我的自定义工具栏类还没有额外的代码,它只是实现了所需的构造函数,所以我自己并不操纵边距 以下是自定义工具栏类: import android.content.Context; import a

在我的项目中,我正在扩展android.support.v7.widget.Toolbar来为类添加一些额外的功能。但是,当我在布局文件中实现此类时,它会更改工具栏上显示的图标的边距(或填充,不确定…)

默认android.support.v7.widget.Toolbar结果:

自定义工具栏类结果:

我的自定义工具栏类还没有额外的代码,它只是实现了所需的构造函数,所以我自己并不操纵边距

以下是自定义工具栏类:

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;


public class ThemedToolbar extends Toolbar {

    public ThemedToolbar(Context context) {
        this(context, null);
    }

    public ThemedToolbar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ThemedToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}
这是我在所有活动中包含的工具栏布局文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="?actionBarSize">

    <com.endare.ui.theme.view.ThemedToolbar
        android:id="@+id/toolbar_control"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white" />

    <RelativeLayout
        android:id="@+id/toolbar_content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/toolbar_logo"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"/>

    </RelativeLayout>

</FrameLayout>


因此,基本上,我在布局文件中所做的只是切换
,您必须将
R.attr.toolbarStyle
作为第二个构造函数中的
defstylettr
参数