Search code examples
androidandroid-actionbarandroid-actionbar-compat

Custom Actionbar View - not filling height


My custom actionbar view is not filling height.. It appears as in the picture.

enter image description here

I am using AppCompatActivity (ActionBarActivity is deprecated).

 ActionBar actionBar = pActivity.getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(pActivity);

    View mCustomView = mInflater.inflate(R.layout.action_new, null);

    TextView text_back = (TextView) mCustomView.findViewById(R.id.text_back);
    text_back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            pActivity.onBackPressed();
        }
    });

    TextView text_reset = (TextView) mCustomView.findViewById(R.id.text_reset);
    text_reset.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
    actionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(mCustomView);
    Toolbar parent = (Toolbar) mCustomView.getParent();
    parent.setContentInsetsAbsolute(0, 0);

Following is the action_new layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@color/bottom_green">    
    <TextView
        android:layout_width="wrap_content" android:layout_height="wrap_content"  android:text="BACK" android:id="@+id/text_back"  android:layout_centerVertical="true" android:layout_alignParentLeft="true"   android:layout_alignParentStart="true" android:textColor="@color/text_in_green" android:padding="10dp" android:textSize="18dp" android:paddingLeft="15dp"
        />    
    <TextView
        android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RESET" android:id="@+id/text_reset" android:textColor="@color/text_in_green" android:textSize="18dp" android:layout_centerVertical="true"  android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:padding="10dp" android:paddingRight="15dp" android:paddingEnd="15dp"
        />
</RelativeLayout>

Solution

  • Quick fix, add android:minHeight="?attr/actionBarSize" to your RelativeLayout

    For better handling and more freely customized, you should use toolbar