可触摸对话框片段下的按钮 - 安卓

时间:2015-09-17 14:24:21

标签: android dialogfragment

我在处理对话框片段时遇到问题。我感谢你!

我的代码如下:

主要活动:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        UnderlayerDialogFragment underlayerDialogFragment = new UnderlayerDialogFragment();
        underlayerDialogFragment.show(getFragmentManager(), "");
    }
}

DialogFragment:

public class UnderlayerDialogFragment extends DialogFragment{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_fragment_underlayer, container, false);
        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        return dialog;
    }
}

主要布局:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:text="Button on main layout"/>
</LinearLayout>

对话框片段布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_material_dark"
    android:alpha="0.5">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Button on DialogFragment layout"/>
</RelativeLayout>

部署后,我的屏幕如下:

enter image description here

我想:

我可以触摸按钮“主要布局上的按钮”和“对话框片段布局上的按钮”

问题:

我可以触摸“对话框片段布局上的按钮”按钮,但我无法触摸“主要布局上的按钮”按钮。

请帮帮我!!!

谢谢!

1 个答案:

答案 0 :(得分:0)

而不是使用android:layout_height =&#34; match_parent&#34;从main和fragment布局尝试使用wrap_content或test with fixed dp

相关问题