1

这是我的 onCreate() 函数:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //inflate the view
    View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_loading, null);     
    TextView loadingMessage = (TextView) view.findViewById(R.id.fragment_loading_message_textview);
    loadingMessage.setText("test");
    //the dialog
    Dialog dialog;
    //set the dialog views
    int themeId = getDialogThemeId();
    //if there is no theme
    if (themeId == -1)
        dialog = new Dialog(getActivity());
    else
        dialog = new Dialog(getActivity(),getDialogThemeId()); 
    //remove background
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    //remove title
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    //set the content view
    dialog.setContentView(view);        
    //set cancel properties
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    return dialog;
}       

这是我正在膨胀的布局:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical" 
    android:background="@android:color/black">

    <!-- spinner -->

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@android:color/transparent" />

    <!-- text -->

    <TextView
        android:id="@+id/fragment_loading_message_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textAppearance="@android:style/TextAppearance.Large"
        android:textColor="@android:color/white" 
        android:text="LOADING"/>

</LinearLayout>

虽然我正在调用 loadingMessage.setText("test") 加载消息一直在消息中向我显示“LOADING”......任何想法?

4

1 回答 1

3

好的,我发现了问题。在同一个 DialogFragment 中,我也实现了 onCreateDialog 和 onCreateView。

这导致我的观点被夸大了两次。因为 onCreateView 在 onCreateDIalog 之后被调用,所以我在 onCreateDialog 中加载的视图被覆盖了。

希望别人会

于 2014-03-09T08:45:51.820 回答