我想調整我AlertDialog.Builder
,但我沒有發現本網站上的任何決定,我都試過了我的問題,看到了像this one但是好像年紀比我在尋找,我在看代碼不現在工作...如何調整AlertDialog.Builder的大小?
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();
}
});
}
}
我試圖成爲AlertDialog.Builder
到AlertDialog
調整其大小,只是沒有顯示數據的黑色正方形。
問題:我應該怎麼做一個AlertDialog.Builder與大文本? (需要滾動是肯定的,因爲我不想讓對話框一樣大,我的屏幕)
修訂:
我想是這樣的,我必須要更改文本Bundle
,我稱之爲AlertDialog從我AppCompatActivity它採用FrameLayout
(我不知道這應該是涵蓋什麼,我需要什麼樣的對話):
更新2 :
最後,我一直在試圖做什麼,我正在尋找下一個代碼,但它仍然無法正常工作......
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");
...............
我的對話框出現時使用默認的佈局(它不具有滾動視圖,也沒有我的興趣大小(只顯示爲默認的Android警告對話框...)
我怎樣才能解決這個問題?我認爲這很愚蠢,但這令人沮喪......無論如何,謝謝!
http://www.mkyong.com/ android/android-custom-dialog-example/ –