为什么PopWindow在活动完成后短时间使屏幕变黑

时间:2017-05-22 05:33:34

标签: android

 private void openInput(View v, String nickname) {
    if (popInputNickName == null) {
        View view = LayoutInflater.from(UserInfoActivity.this).inflate(R.layout.pop_nickname_modify, null);
        popInputNickName = new InputPopWindow(view, LinearLayout.LayoutParams.MATCH_PARENT
                , LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popInputNickName.setAnimationStyle(R.style.NewContentAnim);
        popInputNickName.setBackgroundDrawable(new BitmapDrawable());
        popInputNickName.setFocusable(true);
        popInputNickName.setTouchable(true);
        popInputNickName.setOutsideTouchable(true);

        edit_nickname = (EditText) view.findViewById(R.id.edit_pop_nickname);
        text_commit = (TextView) view.findViewById(R.id.text_pop_commit);
        text_cancel = (TextView) view.findViewById(R.id.text_pop_cancel);

        if (!TextUtils.isEmpty(nickname)) {
            edit_nickname.setText(nickname);
        }

        text_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String nickName = edit_nickname.getText().toString().trim();
                if (!TextUtils.isEmpty(nickName)) {
                    modifyNickName(nickName);
                } else {
                    ToastUtil.Infotoast(UserInfoActivity.this, getString(R.string.null_nickname));
                }
            }
        });

        text_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popInputNickName.dismiss();
            }
        });
    } else {
        if (!TextUtils.isEmpty(nickname)) {
            edit_nickname.setText(nickname);
        }
    }

    popInputNickName.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    popInputNickName.showAtLocation(v, Gravity.BOTTOM, 0, 0);
    edit_nickname.requestFocus();
    InputMethodManager imm = (InputMethodManager) edit_nickname.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    openInputTime = System.currentTimeMillis();
}

the popwindow show

当我参加活动时(称之为A)&显示一个用于修改用户昵称的popwindow。当我完成A时,屏幕会变黑一段时间。但是当我进入A并且没有打开popwindow时,则不会出现黑屏,它会正常完成。所以我想知道是什么导致了这个问题,以及如何解决它。

1 个答案:

答案 0 :(得分:0)

我很抱歉,问题不明确。最后我解决了这个问题。我使用了导致这个问题的自定义视图.PopWindow中的edit_nickname是一个扩展EditText的自定义视图。

public class TfEditView extends EditText {

private OnFinishComposingListener mFinishComposingListener;

public TfEditView(Context context) {
    super(context);
}

public TfEditView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public TfEditView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public void setOnFinishComposingListener(OnFinishComposingListener listener) {
    this.mFinishComposingListener = listener;
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    return new MyInputConnection(super.onCreateInputConnection(outAttrs), false);
}


public class MyInputConnection extends InputConnectionWrapper {

    public MyInputConnection(InputConnection target, boolean mutable) {
        super(target, mutable);
    }

    @Override
    public boolean finishComposingText() {
        boolean finishComposing = super.finishComposingText();
        if (mFinishComposingListener != null) {
            mFinishComposingListener.finishComposing();
        }
        return finishComposing;
    }
}


public interface OnFinishComposingListener {
    void finishComposing();
}

}

private long openInputTime = 0;
private final long canHideTime = 500;
private void openInput(View v, String nickname) {
    if (popInputNickName == null) {
        View view = LayoutInflater.from(UserInfoActivity.this).inflate(R.layout.pop_nickname_modify, null);
        popInputNickName = new InputPopWindow(view, LinearLayout.LayoutParams.MATCH_PARENT
                , LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popInputNickName.setAnimationStyle(R.style.NewContentAnim);

        popInputNickName.setBackgroundDrawable(new BitmapDrawable());
        popInputNickName.setFocusable(true);
        popInputNickName.setTouchable(true);
        popInputNickName.setOutsideTouchable(true);

        edit_nickname = (TfEditView) view.findViewById(R.id.edit_pop_nickname);
        text_commit = (TextView) view.findViewById(R.id.text_pop_commit);
        text_cancel = (TextView) view.findViewById(R.id.text_pop_cancel);

        if (!TextUtils.isEmpty(nickname)) {
            edit_nickname.setText(nickname);
        }
        edit_nickname.setOnFinishComposingListener(new TfEditView.OnFinishComposingListener() {
            @Override
            public void finishComposing() {
                if (popInputNickName != null && popInputNickName.isShowing() && openInputTime != 0 && (System.currentTimeMillis() - openInputTime > canHideTime)) {
                    popInputNickName.dismiss();
                }
            }
        });

        text_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String nickName = edit_nickname.getText().toString().trim();
                if (!TextUtils.isEmpty(nickName)) {
                    modifyNickName(nickName);
                } else {
                    ToastUtil.Infotoast(UserInfoActivity.this, getString(R.string.null_nickname));
                }
            }
        });

        text_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popInputNickName.dismiss();
            }
        });
    } else {
        if (!TextUtils.isEmpty(nickname)) {
            edit_nickname.setText(nickname);
        }
    }

    popInputNickName.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    popInputNickName.showAtLocation(v, Gravity.BOTTOM, 0, 0);
    edit_nickname.requestFocus();
    InputMethodManager imm = (InputMethodManager) edit_nickname.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    openInputTime = System.currentTimeMillis();
}

在上面的代码中,popindow可以从popwindow开始显示的时间超过500毫秒。