I'd like to resize my AlertDialog.Builder
but I didn't find any resolution on this website, I tried everything I saw on questions like this one but seems older than I'm looking for, The code I'm watching doesn't work right now...
ALERTDIALOGBUILDER.JAVA
public class AlertDialogInfo extends AlertDialog.Builder {
public AlertDialogInfo(Context context, String title, String msg) {
super(context);
AlertDialog.Builder builder = new AlertDialog.Builder(context,R.style.AppCompatAlertDialogStyle);
builder.setTitle(title);
builder.setMessage(msg);
builder.setNegativeButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
}
}
I tried to become AlertDialog.Builder
to AlertDialog
to resize it, but just displays a black square without data.
QUESTION: What should I do to make an AlertDialog.Builder with a large text? (need to scroll that sure, because I don't want to make the dialog as big as my screen)
UPDATED:
What I want is something like this, I HAVE TO CHANGE THE TEXT by Bundle
, I call the AlertDialog from my AppCompatActivity which uses FrameLayout
(I don't know what kind of Dialog it should be to cover what I need):
UPDATED 2:
Finally I've been trying to do what I'm looking for with the next code, but it still doesn't work...
ALERT_DIALOG.XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="250dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical">
<TextView
android:id="@+id/msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp" />
</LinearLayout>
MYALERTDIALOG.JAVA
public class MyDialogFragment extends DialogFragment {
public static MyDialogFragment newInstance(String text) {
MyDialogFragment frag = new MyDialogFragment();
Bundle args = new Bundle();
args.putString("TEXT", text);
System.out.print("Text dentro de newInstance: " + text);
frag.setArguments(args);
return frag;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String sinopsis = getArguments().getString("TEXT");
System.out.print("Text dentro de onCreateDialog: " + text);
return new AlertDialog.Builder(getActivity())
.setIcon(android.R.drawable.ic_dialog_info)
.setTitle("TITLE")
.setMessage(text)
.setNegativeButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismiss();
}
}
) .create();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.alert_dialog, container);
}
}
ActivityWhereDialogIsBeenCalled.java
........
DialogFragment frag = MyDialogFragment.newInstance("MY MESSAGE");
frag.show(getSupportFragmentManager(),"TAG");
...............
My dialog appears using DEFAULT LAYOUT (It doesn't have scrollview nor my interested size (just shows as default android alert dialog...)
How can I resolve this question? I think that's silly, but it's frustating... Thanks anyway!