0

我正在使用 Crouron 库,并且我的操作栏设置为 FEATURE_ACTION_BAR_OVERLAY,如何将 Crouton 设置为从操作栏下方开始?,我尝试使用 marginTop 作为自定义视图,这是我的代码:

 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" />

但是,视图似乎仍然从操作栏后面弹出,我很清楚,知道吗?

4

1 回答 1

6

Crouton 可以附加到 ViewGroup。所以在你的例子中,因为你已经android:layout_marginTop="?attr/actionBarSize"在你的根布局中设置了,你只需要在你的根布局中添加一个 id,在你的代码中获取引用并添加到 Crouton。

代码示例:

LinearLayout rootLayout = (LinearLayout) findViewById(R.id.my_root_layout);
Crouton.showText(this, "myText", Style.INFO, rootLayout);
于 2014-08-19T14:08:11.937 回答