Make AlertDialog Custom

2020-06-06 05:56发布

I am using this code to display Alert Dialog

  holder.tv1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AlertDialog.Builder nointernetconnection = new AlertDialog.Builder(
                                temp);
                        nointernetconnection
                                .setIcon(R.drawable.ic_launcher)
                                .setTitle(list.get(position).getAS_name())
                                .setMessage(list.get(position).getDesc_art())
                                .setCancelable(true)
                                .setPositiveButton("OK",
                                        new DialogInterface.OnClickListener() {
                                                   @Override
                                            public void onClick(DialogInterface arg,
                                                    int arg1) {



                                            }
                                        });
                        AlertDialog a = nointernetconnection.create();
                        a.show();

enter image description here

Message body is converted into scrollView automatically in case the text is more but Title text has not been viewed completely nor the title space is scrollable.

So, I want to expand the Title area & also want to make it scrollable & for this i don't wanna use custom Dialog, i want to only implement it by AlertDialog.

7条回答
叛逆
2楼-- · 2020-06-06 06:51

You can import a layout completely in a dialog, if you want u can set a title to dialog or put a text field in layout acting as title.

LayoutInflater factory = LayoutInflater.from(context);
        final View textEntryView = factory.inflate(your_layout_id, null);
        Builder builder = new Builder(context);
        builder.setTitle(title);//Optional can be added in layout


        mAlertDialog = builder.create();
        mAlertDialog.setCancelable(false);
        mAlertDialog.setView(textEntryView, 10, 10, 10, 10);
查看更多
登录 后发表回答