Warning message not showing in warning dialog?

I want to display a warning dialog for the device screen size. I got a solution from this link. How to make a notification dialog fill 90% of the screen size? I use the solution given there, it works fine, but my warning message displays in very small sizes. we can't even parse the message in landscape orientation. I used the following code.

AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.app_description).setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); builder.Title(title); Dialog d = builder.setView(new View(this)).create(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; d.show(); d.getWindow().setAttributes(lp); 

How to set a message so that it is displayed correctly in a dialog box?

Thanks in advance Pushpa

+1
source share
2 answers

Check out this code and tell me what you really wanted to achieve?

  AlertDialog.Builder builder = new AlertDialog.Builder(this); // Creates textview TextView text = new TextView(this); text.setText("Hello This text"); text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); text.setTextSize(20); text.setGravity(Gravity.CENTER); //Creates a linearlayout layout and sets it with initial params LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); ll.setGravity(Gravity.CENTER); ll.addView(text); //adds textview to llayout builder.setMessage("Title").setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); Dialog d = builder.setView(ll).create(); //Fills up the entire Screen WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; d.show(); d.getWindow().setAttributes(lp); 
0
source

By default for an implementation-ion, you cannot set the text size. you can do one simple thing. wirte XML and inflate this XML and move on to the constructor view.

  builder.setView(view) 

nothing but a dialogue setting. and this view will handle all touches. and you can specify the height and width of the representations in xml, including the size of the text.

+1
source

Source: https://habr.com/ru/post/914894/


All Articles