4

我一直在思考面包块,在创建 customView crouton 弹出窗口后,我注意到了两件事;- 布局在创建时略有修改,如果视图更新,将更正 - 无法添加样式来制作自定义油炸面包丁,或者我不知道......有人请提供一种方法来做每一个这些整齐

面包块创建代码:

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();

布局代码:

<?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>

4

3 回答 3

10

尝试使用以下代码

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();

    }
});
于 2014-11-06T10:17:58.990 回答
4

我将此代码用于我的面包块:
您可以使用此代码:

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();
于 2014-04-23T16:48:24.623 回答
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.

于 2013-11-12T11:50:45.600 回答