如何使用库或 class 在 android 中创建自定义对话框?
How to create a Custom Dialog box in android with library or class?
我想创建一个如下所示的自定义对话框
我需要一个具有以下功能的对话框
- 右边header文字可以改
- 左边header图片可以改
- 可以更改header背景颜色和高度
- 内容文本&文本颜色和背景颜色可以更改
最后可以更改按钮文本和颜色
不管是图书馆还是Javaclass
如果你有具有这些功能的库请介绍一下
请使用 android 中的 DialogFragment Class
以正确的方式构建自定义对话框。
A fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
实施应覆盖此 class 并实施 onCreateView(LayoutInflater, ViewGroup, Bundle) 以提供对话框的内容。或者,他们可以覆盖 onCreateDialog(Bundle) 以创建一个完全自定义的对话框,例如具有自己内容的 AlertDialog。 Source -
您可以创建一个新的 activity 对话框主题。在那里你可以自由地设计,因为你有布局。
您可以使用带有自定义布局的常规 Android 对话框。为此,请使用您想要的布局创建一个 xml 文件,然后使用 LayoutInflater
和 Dialog
来显示它。 Reference.
好吧,这就是我的做法(我的方式)
public class ReconnectDialog extends DialogFragment {
private final static String TAG = ReconnectDialog.class.getSimpleName();
Dialog dialog;
public ReconnectDialog(){
// can be custom
}
public void show(){
dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.reconnect_dialog);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
public void dismiss(){
if (dialog != null)
dialog.dismiss();
else
Log.i(TAG, "dialog is null...");
}
public boolean isDismissed(){
return dialog != null && !dialog.isShowing();
}
}
我想创建一个如下所示的自定义对话框
我需要一个具有以下功能的对话框
- 右边header文字可以改
- 左边header图片可以改
- 可以更改header背景颜色和高度
- 内容文本&文本颜色和背景颜色可以更改 最后可以更改按钮文本和颜色
不管是图书馆还是Javaclass 如果你有具有这些功能的库请介绍一下
请使用 android 中的 DialogFragment Class
以正确的方式构建自定义对话框。
A fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
实施应覆盖此 class 并实施 onCreateView(LayoutInflater, ViewGroup, Bundle) 以提供对话框的内容。或者,他们可以覆盖 onCreateDialog(Bundle) 以创建一个完全自定义的对话框,例如具有自己内容的 AlertDialog。 Source -
您可以创建一个新的 activity 对话框主题。在那里你可以自由地设计,因为你有布局。
您可以使用带有自定义布局的常规 Android 对话框。为此,请使用您想要的布局创建一个 xml 文件,然后使用 LayoutInflater
和 Dialog
来显示它。 Reference.
好吧,这就是我的做法(我的方式)
public class ReconnectDialog extends DialogFragment {
private final static String TAG = ReconnectDialog.class.getSimpleName();
Dialog dialog;
public ReconnectDialog(){
// can be custom
}
public void show(){
dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.reconnect_dialog);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
public void dismiss(){
if (dialog != null)
dialog.dismiss();
else
Log.i(TAG, "dialog is null...");
}
public boolean isDismissed(){
return dialog != null && !dialog.isShowing();
}
}