【问题标题】:DialogFragment Blank and greyed out on MarshmallowDialogFragment 空白并在棉花糖上变灰
【发布时间】:2016-07-06 20:29:12
【问题描述】:

我有一个通用主菜单,当按下图像时会使用对话框片段弹出。这在使用 5.1 Lollipop 的 Galaxy Tab S2 9.7 平板电脑上没有问题。但是,升级到 6.0.1 后它不再弹出。相反,菜单看起来像是要弹出,屏幕变暗,就像菜单在那里一样,但屏幕上什么也没有。当我触摸屏幕时,屏幕会变亮并让我回到原来的主要活动,就像我在 DialogFragment 之外单击一样。

我已经检查了我的所有代码,并且一切都从我所看到的中检查出来。我想知道这是否可能是对话框本身的问题,而不是调用活动的问题。

这是调用活动的代码:

optionMenu = (ImageView) findViewById(R.id.optionGear);
optionMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            Fragment prev = getFragmentManager().findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }

            DialogFragment editNameDialog = MainMenuDialog.newInstance("Set Event ID");
            //MainMenuDialog editNameDialog = MainMenuDialog.newInstance("Set Event ID");
            Bundle args = new Bundle();
            args.putString("ID", eventID);
            editNameDialog.setArguments(args);
            editNameDialog.show(ft, "dialog");

        }
    });

这是来自对话框的一段代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_main_menu, container);



}

@Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

这是 XML 的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/options_menu"
android:layout_width="290dp" android:layout_height="460dp"
android:layout_gravity="center" android:orientation="vertical"
android:background="#7bffffff"
android:visibility="visible">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:enabled="false" />

<TextView
    android:id="@+id/textView4"
    android:text="EVENT INFORMATION"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textStyle="bold"
    android:typeface="sans"
    android:textColor="#ffffff"
    android:textAlignment="center"
    android:background="#ce2127" />

<TextView
    android:id="@+id/lbl_your_name" android:text="Event ID: (Must be in all caps)"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="20sp"
    android:textColor="#000000"
    android:layout_marginTop="10dp"
    android:textAlignment="center" />

<EditText
    android:id="@+id/event_id"
    android:layout_width="match_parent"  android:layout_height="wrap_content"
    android:inputType="text|textCapCharacters"
    android:imeOptions="actionDone"
    android:textColor="#000000"
    android:textAlignment="center" />

<TextView
    android:id="@+id/textView2"
    android:text="Re-Enter Event ID:"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:textSize="20sp"
    android:textColor="#000000"
    android:textAlignment="center" />

<EditText
    android:id="@+id/confirmEvent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text|textCapCharacters"
    android:imeOptions="actionDone"
    android:textColor="#000000"
    android:textAlignment="center" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:gravity="center_horizontal">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:text="CLEAR TEXT"
        android:id="@+id/clearButton"
        android:background="#a0a0a0"
        android:textColor="#ffffff" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:text="CANCEL"
        android:id="@+id/cancelButton"
        android:background="#ce2127"
        android:textColor="#ffffff"
        android:layout_marginLeft="15dp"
        android:layout_gravity="center_horizontal" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:text="SAVE"
        android:id="@+id/saveButton"
        android:background="#009634"
        android:textColor="#ffffff"
        android:layout_marginLeft="15dp"
        android:layout_gravity="right" />

</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:id="@+id/textView3"
    android:enabled="false"
    android:background="#000000"
    android:layout_marginTop="10dp" />

<TextView
    android:id="@+id/uploadTitle"
    android:text="NON-UPLOADED VIDEOS"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textStyle="bold"
    android:typeface="sans"
    android:textColor="#ffffff"
    android:textAlignment="center"
    android:background="#ce2127"
    android:layout_marginBottom="10dp" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="# VIDEOS TO UPLOAD:"
        android:id="@+id/textView5"
        android:textSize="20sp"
        android:textStyle="bold"
        android:textColor="#000000" />

    <TextView
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:text="0"
        android:id="@+id/videoCount"
        android:textSize="20sp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:textAlignment="textEnd" />
</LinearLayout>

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="CLICK TO UPLOAD VIDEOS"
    android:id="@+id/uploadButton"
    android:textStyle="bold"
    android:textColor="#000000"
    android:textSize="20sp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp" />

<TextView
    android:id="@+id/uploadStatus"
    android:text="UPLOAD STATUS: IDLE"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:textSize="20sp"
    android:textStyle="bold"
    android:typeface="sans"
    android:textColor="#000000"
    android:textAlignment="center" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal">

    <TextView
        android:id="@+id/textView6"
        android:text="Application Version: "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        android:textStyle="bold"
        android:typeface="sans"
        android:textColor="#000000"
        android:textAlignment="center"
        android:layout_marginTop="10dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/verNumber"
        android:textSize="15sp"
        android:textStyle="bold"
        android:typeface="sans"
        android:layout_marginTop="10dp" />
</LinearLayout>

我过去曾看到这些三星设备由于 Touchwiz 覆盖而出现奇怪的故障。

任何帮助将不胜感激!

【问题讨论】:

    标签: android android-fragments android-6.0-marshmallow android-dialogfragment


    【解决方案1】:

    包装对我不起作用,但我最终通过添加 requestFeature(Window.FEATURE_NO_TITLE) 来修复它:

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)
        dialog.window.requestFeature(Window.FEATURE_NO_TITLE)
        return dialog
    }
    

    【讨论】:

      【解决方案2】:

      事实证明,Android 6.0.1 从我选择的线性布局开始的 XML 布局存在问题。

      我最终将线性布局包装在标准 FrameLayout 和 BAM 中,一切都显示出来了!

      有趣....

      <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/options_menu"
      android:layout_width="290dp" android:layout_height="460dp"
      android:layout_gravity="center" android:orientation="vertical"
      android:background="#7bffffff">>
      

      【讨论】:

        猜你喜欢
        • 2018-09-08
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 2017-02-02
        • 1970-01-01
        • 1970-01-01
        • 2016-03-15
        相关资源
        最近更新 更多