Android 工具栏菜单项间距问题

Android 工具栏菜单项间距问题,android,android-layout,Android,Android Layout,我的Android应用程序中有一个工具栏,其中有一个自定义菜单项,如下所示: <group android:checkableBehavior="single"> <item android:id="@+id/todayIcon" android:title="" app:actionViewClass="com.anubavam.creatrix.modules.calendar.view.TodayMenuTextVi

我的Android应用程序中有一个工具栏,其中有一个自定义菜单项,如下所示:

<group android:checkableBehavior="single">
    <item
        android:id="@+id/todayIcon"
        android:title=""
        app:actionViewClass="com.anubavam.creatrix.modules.calendar.view.TodayMenuTextView"
        app:showAsAction="always" />

</group>
这是我的
TodayMenuTextView
课程:

public class TodayMenuTextView extends android.support.v7.widget.AppCompatTextView {
    public TodayMenuTextView(Context context) {
        super(context);
        init();
    }

    public TodayMenuTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TodayMenuTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setBackground(ContextCompat.getDrawable(getContext(), R.drawable.ic_go_to_today));
        setMaxLines(1);
        setFilters(new InputFilter[]{new InputFilter.LengthFilter(1)});
        setTextColor(Color.WHITE);
        setPadding(0, 10, 0, 0);
        setGravity(Gravity.CENTER);
        setTextSize(12);
        requestLayout();
    }
}
这是我的输出:

我的菜单项位于工具栏的右侧。此外,菜单项“单击”不起作用


如何将菜单项a添加到右边距并解决单击问题?

将LayoutParams设置为菜单项

  LayoutParams params = new LayoutParams(
    LayoutParams.WRAP_CONTENT,      
    LayoutParams.WRAP_CONTENT
   );
 params.setMargins(left, top, right, bottom);
 yourImageBiew.setLayoutParams(params);

在文本视图(即2)中设置padding all 0text,在将所有padding设置为零时做些什么。我看不出图片中有任何问题您只是使用顶部padding,而不是使用setPadding(10,10,10,10);
  LayoutParams params = new LayoutParams(
    LayoutParams.WRAP_CONTENT,      
    LayoutParams.WRAP_CONTENT
   );
 params.setMargins(left, top, right, bottom);
 yourImageBiew.setLayoutParams(params);