Search code examples
androidandroid-actionbarcrouton

Crouton with action bar overlay


I am using the Crouron library and my action bar is set to FEATURE_ACTION_BAR_OVERLAY, how can i set the Crouton to start from below the action bar?, i tried using marginTop for the custom view, here is my code:

 LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        tools:ignore="Overdraw"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:layout_marginTop="?attr/actionBarSize"
        android:background="@layout/round_edges_solid_grey_back"
        android:padding="10dp">

      <ImageView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/cruton_image"
          android:src="@drawable/ic_launcher"
          />

      <LinearLayout android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:layout_marginLeft="5dp"
          android:orientation="vertical">

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:id="@+id/cruton_text_a"
        android:textColor="#fff"
        android:text="asa" />

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#fff"
    android:id="@+id/cruton_text_b"
    android:text="sdfgs" />

however the view still seems to pop from behind the action bar and i bearly see it, any idea?


Solution

  • A Crouton can be attached to a ViewGroup. So in your example, since your already set android:layout_marginTop="?attr/actionBarSize" in your root layout, you just have to add an id to your Root-Layout, get the reference in your code and add in to the Crouton.

    Code-Example:

    LinearLayout rootLayout = (LinearLayout) findViewById(R.id.my_root_layout);
    Crouton.showText(this, "myText", Style.INFO, rootLayout);