簡體   English   中英

如何在Android中所有屏幕尺寸的底部設置彈出窗口?

[英]how to set popup window at the bottom of all screen size in Android?

我在應用程序中創建camerapopup.xml。 我想在所有屏幕尺寸的屏幕底部顯示此彈出窗口。 我試圖創建不同的布局文件夾(layout-large,layout-small,layoutxlarge等),但根本不起作用如何在底部為所有屏幕尺寸設置彈出窗口。有人可以幫我如何使用它。提前致謝 。

這是我的xml文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_element"
    android:layout_width="fill_parent"
    android:layout_height="180dp"
    android:background="@android:color/transparent"
    android:orientation="vertical"
    android:padding="3dp">


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="1dp"
        android:background="@android:color/transparent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/Title"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:background="@drawable/curve_shap"
            android:gravity="center_horizontal|center_vertical"
            android:text="Take Photo"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/darker_gray"
            android:textSize="14sp" />

        <Button
            android:id="@+id/button_Camera"
            android:layout_width="fill_parent"
            android:layout_height="40dp"

            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:background="@drawable/curve_shap"
            android:text="Camera"
            android:textColor="#3A86CF" />

        <Button
            android:id="@+id/button_Gallery"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:background="@drawable/curve_shap"
            android:text="Gallery"
            android:textColor="#3A86CF" />


    </LinearLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="45dp"
        android:layout_marginTop="4dp"
        >

        <Button
            android:id="@+id/btnCancelCamera"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"

            android:background="@drawable/curve_shap"
            android:text="Cancel"
            android:textColor="#3A86CF"
            android:textSize="16sp"
            android:textStyle="bold" />
    </RelativeLayout>


</LinearLayout>

這是我的活動代碼

imgProfilePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

 LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
                View popupView = layoutInflater.inflate(R.layout.camera_popup, (ViewGroup) findViewById(R.id.popup_element));
                popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                popupWindow.setWidth(720);
                popupWindow.setHeight(350);
                popupWindow.setFocusable(true);
                popupWindow.showAtLocation(popupView, Gravity.BOTTOM, 0, 0);
                popupWindow.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

                Button btnCamera = (Button) popupView.findViewById(R.id.button_Camera);
                Button btnGallery = (Button) popupView.findViewById(R.id.button_Gallery);
                Button btnDismiss = (Button) popupView.findViewById(R.id.btnCancelCamera);
}
        });
Use this in all your java file 

AlertDialog.Builder builder = new AlertDialog.Builder(context);
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        View dialogLayout = inflater.inflate(R.layout.ppopup_element,
                null);

        final AlertDialog dialog = builder.create();
        dialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        dialog.setView(dialogLayout, 0, 0, 0, 0);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        WindowManager.LayoutParams wlmp = dialog.getWindow()
                .getAttributes();
        wlmp.gravity = Gravity.BOTTOM;


          Button btnCamera = (Button) dialogLayout.findViewById(R.id.button_Camera);
            Button btnGallery = (Button) dialogLayout.findViewById(R.id.button_Gallery);
            Button btnDismiss = (Button) dialogLayout.findViewById(R.id.btnCancelCamera);


        builder.setView(dialogLayout);

        dialog.show();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM