How to add title to the custom Dialog?

后端 未结 7 585
猫巷女王i
猫巷女王i 2021-01-12 20:37

How can i add title to this custom dialog??

\"enter

I have tried like this

相关标签:
7条回答
  • Why not use an AlertDialog if you have 3 or less buttons?

    My AlertDialog looks like this:

    enter image description here

    My java code:

    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.add_filter, null);
    
    AlertDialog alertDialog = new AlertDialog.Builder(this)
            .create();
    alertDialog.setTitle("AlertDialog title");
    alertDialog.setMessage("AlertDialog message");
    alertDialog.setView(view);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();
    

    My XML:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >
    
        <Spinner
            android:id="@+id/spinner_filter"
            android:layout_width="wrap_content"
            android:spinnerMode="dropdown"
            android:layout_height="wrap_content"
            android:entries="@array/filter_array"
            android:prompt="@string/filter_prompt" />
    
    </LinearLayout>
    

    Simple yet does what you need.

    0 讨论(0)
提交回复
热议问题