【问题标题】:getSupportActionBar().setCustomView(view, layout); does not cover entire actionbargetSupportActionBar().setCustomView(view, layout);不覆盖整个操作栏
【发布时间】:2014-12-05 05:37:22
【问题描述】:

我正在尝试设置自定义操作栏背景,但它并没有填满整个空间。 它从左侧留下一个 5dp 的灰色操作栏。 我使用了以下内容:

 android.support.v7.app.ActionBar.LayoutParams layout = new android.support.v7.app.ActionBar.LayoutParams(android.support.v7.app.ActionBar.LayoutParams.FILL_PARENT, android.support.v7.app.ActionBar.LayoutParams.FILL_PARENT);
        getSupportActionBar().setCustomView(view, layout);
        getSupportActionBar().setDisplayShowCustomEnabled(true);

这是我的自定义操作栏 xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="fill_horizontal"
    android:background="@color/actionbar_color"
    ></RelativeLayout>

我尝试了不同的风格,但都没有奏效。 请帮忙

【问题讨论】:

    标签: android-layout android-custom-view android-appcompat android-actionbar-compat


    【解决方案1】:

    通过以下方式修复它:

    //to set same background color on entire actiobar
    getSupportActionBar().setBackgroundDrawable( getResources().getDrawable(R.drawable.actionbar_color));
    
    //to display custom layout with same BG color
    android.support.v7.app.ActionBar.LayoutParams layout = new android.support.v7.app.ActionBar.LayoutParams(android.support.v7.app.ActionBar.LayoutParams.FILL_PARENT, android.support.v7.app.ActionBar.LayoutParams.FILL_PARENT);
            getSupportActionBar().setCustomView(view, layout);
            getSupportActionBar().setDisplayShowCustomEnabled(true);
    

    【讨论】:

    • 您在 setCustomView(view, layout) 中传递的“视图”是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多