Android 如何使自定义alertdialog全屏显示
我希望将自定义的Android 如何使自定义alertdialog全屏显示,android,android-alertdialog,android-dialog,Android,Android Alertdialog,Android Dialog,我希望将自定义的AlertDialog全屏设置为新的活动屏幕 尝试了这些答案,但仍然不起作用 public void newDialog(最终上下文c){ 最终警报对话框警报对话框; LayoutInflater LayoutInflater=LayoutInflater.from(c); dialogueView=LayoutFlater.充气(R.layout.layout_对话,空); 最终AlertDialog.Builder alertDialogBuilder=新建Aler
AlertDialog
全屏设置为新的活动屏幕
尝试了这些答案,但仍然不起作用
public void newDialog(最终上下文c){
最终警报对话框警报对话框;
LayoutInflater LayoutInflater=LayoutInflater.from(c);
dialogueView=LayoutFlater.充气(R.layout.layout_对话,空);
最终AlertDialog.Builder alertDialogBuilder=新建AlertDialog.Builder(c);
alertDialogBuilder.setView(dialogueView);
alertDialog=alertDialogBuilder.create();
dialogueView.findViewById((R.id.closeBtn)).setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
alertDialog.disclose();
}
});
alertDialog.show();
}
layout_dialogue.xml
style.xml
真的
真的
真的
我也试过了
android.R.style.Theme\u黑色\u NoTitleBar\u全屏
ViewGroup.LayoutParams params=getDialog().getWindow().getAttributes();
params.width=WindowManager.LayoutParams.MATCH\u父项;
params.height=WindowManager.LayoutParams.MATCH\u父项;
他们都不是为我工作的。关于如何完成它有什么建议吗?你可以使用自定义样式,让我给你举个例子 style.xml
<style name="DialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="colorPrimaryDark">@color/appPrimaryColor</item>
<item name="colorPrimary">@color/appPrimaryColor</item>
<!-- Set this to true if you want Full Screen without status bar -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
<!-- This is important! Don't forget to set window background -->
<item name="android:windowBackground">@null</item>
</style>
您可以使用以下方法。(它在Kotlin中定义,但您也可以为Java实现) 在样式中添加以下内容。xml
<style name="DialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
</style>
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="colorPrimaryDark">@color/appPrimaryColor</item>
<item name="colorPrimary">@color/appPrimaryColor</item>
<!-- Set this to true if you want Full Screen without status bar -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">false</item>
<!-- This is important! Don't forget to set window background -->
<item name="android:windowBackground">@null</item>
</style>
我一直在使用的全屏对话没有空白
public class ShareImageEditorDialog extends DialogFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,
android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_share_image, container);
return v;
}
}
要在按钮上显示,请单击
new ShareImageEditorDialog().show(((FragmentActivity)activity).getSupportFragmentManager(), "MyTag");
我认为根据您的要求,您需要使用对话框而不是警报对话框。Dialog提供您使用自己的自定义视图。是的,我实际上可以通过Dialog实现,但是可以使用AlertDialog实现吗?谢谢回答,但是我如何使用带有特定按钮的自定义布局?您可以使用自定义布局示例Dialog=新建对话框(这个,R.style.DialogTheme)对话框。setCustomLayout(R.layout.alert\u layout)是的,这是一个可行的方法。但是,我尝试用alertdialog而不是dialog来完成它。这可能吗?使用name=“android:windowIsFloating”>时效果更好。好安寿。谢谢
new ShareImageEditorDialog().show(((FragmentActivity)activity).getSupportFragmentManager(), "MyTag");