PopUpWindow显示不正确

时间:2017-01-06 19:47:19

标签: java android android-layout android-popupwindow

我正在尝试复制此视图的此布局(不一定是editText框的圆角矩形,只是宽度/布局):

enter image description here

暗淡的背景色,即editText的宽度。但是,我得到了这个:

enter image description here

没有透明的背景色,用户可以访问弹出窗口后面的视图,并且editTexts会缩小。这个弹出窗口是从片段中调用的。

1。我不希望用户能够触摸调用片段,因此我使用了:

mPopupWindow.setOutsideTouchable(false);

但是用户仍然可以访问弹出窗口后面的视图。而且我认为这是因为背景尚未确定。所以我这样做了:

以下是相关的代码段(完整代码位于底部)。

2。对于背景颜色:

在我的colors.xml中,我有这个:

 < color name="COLOR_50_GREY" >#80636363</color> 

根据this SO question,您可以创建透明度。但我也尝试过标准颜色。

我用:

调用了那种颜色(或android默认颜色)
mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.COLOR_50_GREY)));

但没有运气。

第3。缩小文本视图。根据{{​​3}}

我应该可以使用下面的内容创建一个加权的LinearLayout(为了清晰起见,明显删除的内容,底部是完整代码):

 <LinearLayout
    android:orientation="horizontal"
    android:weightSum="5">

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

    <EditText
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"/>

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"/>

</LinearLayout>

但正如您从上面的屏幕截图中看到的那样,权重不受尊重。

有任何帮助吗?

如何从我的片段中调用我的弹出窗口

private void showCompeletPopup() {

        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View customView = inflater.inflate(R.layout.popup_close_ticket, null);

        mPopupWindow = new PopupWindow(customView, LinearLayoutCompat.LayoutParams.MATCH_PARENT, LinearLayoutCompat.LayoutParams.WRAP_CONTENT);

        // Set an elevation value for popup window call requires API level 21
        if (Build.VERSION.SDK_INT >= 21) {
            mPopupWindow.setElevation(5.0f);
        }

        mPopupWindow.setOutsideTouchable(false);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.COLOR_50_GREY)));

        mPopupWindow.showAtLocation(getView(), Gravity.CENTER, 0, 0);
}

弹出窗口XML

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/COLOR_LIGHT_GREY"
            android:padding="8dp"
            android:layout_margin="20dp"
            android:scrollbars="none">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginBottom="5dp"
            android:orientation="horizontal"
            android:padding="3dp"
            android:weightSum="5">

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginEnd="4dp"
                android:layout_weight="1"
                android:text="TOW TICKET:"
                android:gravity="right|center_vertical"
                android:textAllCaps="true"
                android:textColor="@color/COLOR_BLUE"
                android:textIsSelectable="false"
                android:textStyle="bold"/>


            <EditText
                android:id="@+id/etTowTicketNumber"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="3"
                android:imeOptions="actionDone"
                android:inputType="text"
                android:maxLength="30"
                android:maxLines="1"
                />

            <Button
                android:id="@+id/btnNA"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_gravity="right"
                android:layout_weight="1"
                android:background="@color/COLOR_BLUE"
                android:padding="1dp"
                android:text="NA"
                android:textColor="@color/COLOR_WHITE"
                android:textSize="18sp"
                android:textStyle="bold"/>

        </LinearLayout>


//OTHER STUFF TRUNCATED FOR BREVITY 

    </LinearLayout>

</ScrollView>

1 个答案:

答案 0 :(得分:0)

您需要为编辑文本制作自定义可绘制设计,并将其设置为编辑文本背景,然后才能实现

start_remove = pd.to_datetime('2016-1-4')
end_remove = pd.to_datetime('2016-1-8')

并提示提示&#34;输入值&#34;使用android:提示属性

相关问题