4

I have been pondering with crouton, and after creating a customView crouton popup I have noticed 2 things; - the layout is slightly modified upon creation and would be corrected if the view if updated - there is no way of adding a style to make custom crouton, or no way I know of ... Would someone please provide a way to do each of these neatly

Crouton creat code:

View crouton_view = getLayoutInflater().inflate(R.layout.crouton_layout, null);
Crouton Date_crounton = Crouton.make(this, crouton_view);
crouton_view.setBackgroundColor(Color.rgb(00, 153, 204));
Date_crounton.show();

Layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/crouton_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
    android:layout_width="match_parent"
    android:layout_height="50dp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#b4b4b4" />
</LinearLayout>

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

    <Button
        android:id="@+id/crouton_cancel"
        style="?android:attr/actionButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Cancel"
        android:textSize="14sp" />

    <ImageView
        android:layout_width="1dp"
        android:layout_height="30dp"
        android:layout_gravity="center_vertical"
        android:background="#b4b4b4" />

    <Button
        android:id="@+id/crouton_ok"
        style="?android:attr/actionButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="OK"
        android:textSize="14sp" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="#b4b4b4" />
</LinearLayout>

Devrim
  • 15,345
  • 4
  • 66
  • 74
alk
  • 41
  • 3

3 Answers3

10

Try to use this following code

View customView = getActivity().getLayoutInflater().inflate(R.layout.crouton_addexam, null);
final Configuration CONFIGURATION_INFINITE = new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build();
final Crouton crouton = Crouton.make(getActivity(),customView,R.id.btnTest,CONFIGURATION_INFINITE);
crouton.setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build());
test.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
            crouton.hide();

    }
});
Adro
  • 675
  • 13
  • 27
lance_andrew
  • 215
  • 3
  • 11
  • Thanks @Joseph ALbert Madia for your inputs this really helps. – Jenny Casarino Nov 06 '14 at 10:25
  • @Joseph ALbert Madia Hi, why is infinite configuration provided twice? 1. As a parameter of `make` method 2. As a parameter of `setConfiguration` method – Singed May 11 '15 at 10:08
  • i want to add this to a frame layout like this Crouton.makeText(MainActivity.this, "Please check your internet connection", Style.ALERT, R.id.main_crouton).setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_I‌​NFINITE).build()).sh‌​ow();. How can i achieve that – Kaustubh Bhagwat Oct 06 '17 at 11:15
4

I use this code for my Crouton:
you can use this:

final Configuration CONFIGURATION_INFINITE = new Configuration.Builder()
                              .setDuration(Configuration.DURATION_INFINITE)
                              .build();
final Crouton infiniteCrouton;
infiniteCrouton = Crouton.makeText(this, "TEXT", Style.INFO); 
infiniteCrouton.setConfiguration(CONFIGURATION_INFINITE);
infiniteCrouton.setOnClickListener(new View.OnClickListener() {
                                  @Override
                                  public void onClick(View v) {
                                    Crouton.hide(infiniteCrouton);
                                  }
                                });
infiniteCrouton.show();
rene
  • 41,474
  • 78
  • 114
  • 152
Mostafa Rostami
  • 1,906
  • 20
  • 29
  • i want to add this to a frame layout like this Crouton.makeText(MainActivity.this, "Please check your internet connection", Style.ALERT, R.id.main_crouton).setConfiguration(new Configuration.Builder().setDuration(Configuration.DURATION_INFINITE).build()).show();. How can i achieve that – Kaustubh Bhagwat Oct 06 '17 at 11:11
0

Yes, there is no way to add a Style to a Crouton with a custom view. But you can add a Configuration.

If you want to update the view you'll need to keep a reference outside of the Crouton and update it on your own.

Also I'm not quite sure if using a Crouton as some kind of modal dialog is a good thing from the UX point of view.

Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
  • Thanks for the help, It seems have to add to the library to use style as for the UX point of view, it is how you add crouton and not it by itself, I think the right implementation would look good – alk Nov 13 '13 at 08:33
  • I'm sorry, I don't understand. Is this another question? – Ben Weiss Nov 13 '13 at 09:19