Android AlertDialog Multi Choice Items with custom

2019-03-04 10:18发布

Does anyone know how to customize items in AlertDialog when multi choice items are set with setMultiChoiceItems(...). I would like to change the text size for the items.

Thanks

2条回答
淡お忘
2楼-- · 2019-03-04 10:39

Sure, you can use Dialog.setContentView() to set the content of a dialog to be an arbitrary layout.

Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.yourLayoutId);
dialog.show();

Make yourself a layout file with a components that you want in it and call setContentView on your dialog, passing the name of your layout file.

If you are deadset on AlertDialog you can do something similar with builder.setView()

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
查看更多
成全新的幸福
3楼-- · 2019-03-04 10:43

You can create a custom AlertDialog where you can change the text size of any element. A simple generic example: http://android-codes-examples.blogspot.in/2011/03/how-to-display-custom-dialog-and.html

查看更多
登录 后发表回答