Android show crouton布局位于工具栏

时间:2016-10-10 16:35:27

标签: android

我想在下面的工具栏上使用Crouton这个代码记录在库网站上:

Crouton.makeText(activity, "MY TEXT", Style.ALERT, toolbar).show();

它显示我Toolbar的顶部,我无法改变其位置,请帮帮我,谢谢

enter image description here

我的布局xml:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <variable
            name="viewModel"
            type="com.pishguy.androidapplication.cafemaku.Views.Activities.ActivityRegister.RegisterViewModel"/>
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/root_layout">

        <include layout="@layout/application_toolbar"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="20dp"
            android:gravity="center"
            android:orientation="vertical">

            <EditText
                android:id="@+id/user_registered_mobile_number"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:background="@drawable/shape_register_edit_box_style"
                android:gravity="center"
                android:hint="@{viewModel.hint}"
                android:textColorHint="@color/black_35"
                android:textSize="12sp"
                android:inputType="phone"/>

            <com.pishguy.androidapplication.cafemaku.Libraries.CircularProgressButton.dd.CircularProgressButton
                android:id="@+id/continue_register"
                android:layout_width="match_parent"
                android:layout_height="35dp"
                android:layout_marginTop="20dp"
                android:background="@drawable/selector_blue_buttons"
                android:gravity="center"
                android:onClick="@{viewModel.onRegisterAccount}"
                android:textColor="#ffffff"
                android:textSize="12sp"
                app:cpb_cornerRadius="25dp"
                app:cpb_textComplete="@string/complete_register"
                app:cpb_textError="@string/error_register"
                app:cpb_textIdle="@string/continue_register"/>
        </LinearLayout>
    </LinearLayout>
</layout>

我的工具栏布局是:

<android.support.design.widget.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:titleTextColor="#ffffff">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal">

            <com.pishguy.androidapplication.cafemaku.Widgets.FontAwesome
                android:id="@+id/icon_search"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginRight="15dp"
                android:clickable="true"
                android:gravity="center|right"
                android:paddingLeft="12dp"
                android:paddingRight="12dp"
                android:shadowColor="#22000000"
                android:shadowDx="3"
                android:shadowDy="3"
                android:shadowRadius="1"
                android:text="&#xf002;"
                android:textColor="#ffffff"
                android:textSize="22sp"/>

        </LinearLayout>
    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabsLayout"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimary"
        app:tabGravity="fill"
        app:tabMode="fixed"/>

</android.support.design.widget.AppBarLayout>

1 个答案:

答案 0 :(得分:0)

添加此FrameLayout;

<FrameLayout
            android:id="@+id/fl_crouton_anchor"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
工具栏下方的

,并将其用作Crouton makeText(Activity activity, int textResourceId, Style style, ViewGroup viewGroup)

中的ViewGroup