Android DialogFragment在“活动”窗口上不浮动
我创建了一个扩展DialogFragment类的类,我的代码如下,我的问题是对话框隐藏在状态栏(在系统中)和工具栏(在活动中),我在这里提到的问题是添加Android DialogFragment在“活动”窗口上不浮动,android,android-dialogfragment,Android,Android Dialogfragment,我创建了一个扩展DialogFragment类的类,我的代码如下,我的问题是对话框隐藏在状态栏(在系统中)和工具栏(在活动中),我在这里提到的问题是添加onCreate函数并设置样式,但对话框仍然只隐藏在工具栏下,不像教程中说的那样,它将浮动在活动窗口上 public class PasswordDialog extends DialogFragment { ...... public static PasswordDialog newInstance(PdfFragment pdfFragme
onCreate
函数并设置样式,但对话框仍然只隐藏在工具栏下,不像教程中说的那样,它将浮动在活动窗口上
public class PasswordDialog extends DialogFragment {
......
public static PasswordDialog newInstance(PdfFragment pdfFragment) {
Log.i(sClassTag,"newInstance in PdfFragmentPasswordDialog");
PdfFragmentPasswordDialog passwordDialog = new PdfFragmentPasswordDialog();
passwordDialog.mPdfFragment = pdfFragment;
setInteractionListener(pdfFragment);
return passwordDialog;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Pick a style based on the num.
int style = DialogFragment.STYLE_NORMAL, theme = 0;
setStyle(style, theme);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i(sClassTag,"onCreateView in PdfFragmentPasswordDialog");
// Inflate the layout to use as dialog or embedded fragment
mView = inflater.inflate(R.layout.layout_password, container, false);
addButtonListener();
addEdittextListener();
return mView;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Log.i(sClassTag,"onCreateView in onCreateDialog");
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
void showPasswordDialog(boolean isFirstTime) {
....
FragmentManager fragmentManager = getActivity().getFragmentManager();
show(fragmentManager, "dialog");
...
}
布局文件是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/ic_img_passwordkey_48"
android:id="@+id/key_icon"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:contentDescription="@string/password_input_hint_message"/>
<Space
android:layout_width="match_parent"
android:layout_height="16dp" />
<EditText
android:imeOptions="flagNoExtractUi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textColorHint="@color/password_dialogUI_hint_text_color"
android:textColor="@color/password_dialogUI_text_color"
android:textSize="12sp"
android:hint="@string/password_input_hint_message"
android:ems="10"
android:id="@+id/dialogUI_edit_text"
android:textCursorDrawable="@null"
android:fontFamily="sans-serif"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:textDirection="locale"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/password_error_warning_message"
android:textColor="@color/password_dialogUI_warning_color"
android:id="@+id/dialogUI_warning_text"
android:textSize="12sp"
android:visibility="invisible"
android:fontFamily="sans-serif"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:layout_marginStart="8dp"/>
<Space
android:layout_width="match_parent"
android:layout_height="8dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp">
<Button
android:text="@string/password_ok_button"
android:textColor="@drawable/layout_disable_text_color"
android:minWidth="64dp"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:id="@+id/password_dialogUI_ok_button"
android:layout_alignParentEnd="true"
style="?android:attr/borderlessButtonStyle"
android:background="@drawable/layout_password_button_background"
android:layout_marginEnd="8dp"/>
<Button
android:text="@string/password_cancel_button"
android:textColor="@drawable/layout_disable_text_color"
android:minWidth="64dp"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:id="@+id/password_dialogUI_cancel_button"
style="?android:attr/borderlessButtonStyle"
android:layout_toStartOf="@+id/password_dialogUI_ok_button"
android:background="@drawable/layout_password_button_background"
android:layout_marginEnd="8dp"/>
2.将android:minWidth和android:minHeight添加到xml中。
见下文:
2.将android:minWidth和android:minHeight添加到xml中。
见下文:
以下是定制DialogFragment的步骤: 1.在方法上从xml膨胀自定义视图
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().setCanceledOnTouchOutside(true);
View view = inflater.inflate(R.layout.XXX,
container, false);
//TODO:findViewById, etc
return view;
}
2.在onResume()中设置对话框的宽度和高度,在onResume()/onStart()中设置rember,在其他方法中似乎不起作用
public void onResume()
{
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(width, height);
window.setGravity(Gravity.CENTER);
//TODO:
}
以下是自定义DialogFragment的步骤: 1.在方法上从xml膨胀自定义视图
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().setCanceledOnTouchOutside(true);
View view = inflater.inflate(R.layout.XXX,
container, false);
//TODO:findViewById, etc
return view;
}
2.在onResume()中设置对话框的宽度和高度,在onResume()/onStart()中设置rember,在其他方法中似乎不起作用
public void onResume()
{
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(width, height);
window.setGravity(Gravity.CENTER);
//TODO:
}
你能给我看“layout\u password.xml”文件吗?请看修改后的问题你能给我看“layout\u password.xml”文件吗?请看修改后的问题谢谢,我尝试直接调用show函数它工作,你节省了我的时间,但我将对话框宽度设置为屏幕宽度的70%,它不工作,你知道如何设置吗?我添加了关于调整碎片大小的对话框。如果你喜欢,你可以选择这个答案为“接受”。谢谢你,我试图直接调用显示功能,它可以工作,你可以保存我的一天,但我设置的对话框宽度为屏幕宽度的70%,它不工作,你知道如何设置吗?我添加了关于调整碎片对话框的大小。如果您喜欢,您可以选择此答案为“已接受”。
public void onResume()
{
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(width, height);
window.setGravity(Gravity.CENTER);
//TODO:
}