首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何创建没有标题的DialogFragment?

如何创建没有标题的DialogFragment?
EN

Stack Overflow用户
提问于 2013-03-08 01:10:51
回答 5查看 83.5K关注 0票数 366

我正在创建一个DialogFragment来显示关于我的应用程序的一些帮助消息。一切正常,除了一件事:在窗口的顶部有一个黑色的条纹,显示DialogFragment,我认为这是为标题保留的,我不想使用的东西。

这是特别痛苦的,因为我的自定义DialogFragment使用白色背景,所以更改太臭名昭著,不能被忽略。

让我以更图形化的方式向您展示:

现在我的DialogFragment的XML代码如下:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:id="@+id/holding" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:background="@drawable/dialog_fragment_bg"
        >
        <!-- Usamos un LinearLayout para que la imagen y el texto esten bien alineados -->
        <LinearLayout
            android:id="@+id/confirmationToast" 
            android:orientation="horizontal" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            >

            <TextView android:id="@+id/confirmationToastText" 
            android:layout_width="wrap_content"
            android:layout_height="fill_parent" 
            android:text="@string/help_dialog_fragment"
            android:textColor="#AE0000"
            android:gravity="center_vertical"
            />

        </LinearLayout>
        <LinearLayout
            android:id="@+id/confirmationButtonLL" 
            android:orientation="horizontal" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:gravity="center_horizontal"
            >    
            <Button android:id="@+id/confirmationDialogButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_marginBottom="60dp"
                android:background="@drawable/ok_button">
            </Button>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

以及实现DialogFragment的类的代码:

public class HelpDialog extends DialogFragment {

    public HelpDialog() {
        // Empty constructor required for DialogFragment
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //Inflate the XML view for the help dialog fragment
        View view = inflater.inflate(R.layout.help_dialog_fragment, container);
        TextView text = (TextView)view.findViewById(R.id.confirmationToastText);
        text.setText(Html.fromHtml(getString(R.string.help_dialog_fragment)));
        //get the OK button and add a Listener
        ((Button) view.findViewById(R.id.confirmationDialogButton)).setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                 // When button is clicked, call up to owning activity.
                HelpDialog.this.dismiss();
             }
         });
        return view;
    }

}

以及在主活动中的创建过程:

/**
 * Shows the HelpDialog Fragment
 */
private void showHelpDialog() {
    android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
    HelpDialog helpDialog = new HelpDialog();
    helpDialog.show(fm, "fragment_help");
}

我真的不知道这个与对话有关的答案是否也适用于这里的Android: How to create a Dialog without a title?

我怎样才能摆脱这个标题区域?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15277460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档