zoukankan      html  css  js  c++  java
  • Android 关于软键盘

     一、.弹出的时候显示Editext框

    添加布局replay_input

       <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/reply_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFF"
    android:orientation="vertical">

    <View
    android:layout_width="match_parent"
    android:layout_height="1px"
    android:background="#80808080" />

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

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


    <EditText
    android:id="@+id/reply"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:paddingRight="30dp" />
    </RelativeLayout>

    <Button
    android:id="@+id/send_msg"
    android:layout_width="50dip"
    android:layout_height="35dp"
    android:layout_margin="5dp"
    android:background="@drawable/master_icon"
    android:text="发送"
    android:textSize="16sp" />
    </LinearLayout>
    </LinearLayout>

    2.编写代码

    private PopupWindow editWindow;
    View editView = mInflater.inflate(R.layout.replay_input, null);
    editWindow = new PopupWindow(editView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    editWindow.setOutsideTouchable(true);
    editWindow.setFocusable(true);
    editWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    EditText replyEdit = (EditText) editView.findViewById(R.id.reply);
    replyEdit.setFocusable(true);
    replyEdit.requestFocus();
    // 以下两句不能颠倒
    editWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    editWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    editWindow.showAtLocation(rlPart, Gravity.BOTTOM, 0, 0);
    // 显示键盘
    final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

    editWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
    @Override
    public void onDismiss() {
    if (imm.isActive())
    imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
    }
    });
  • 相关阅读:
    BZOJ3312: [Usaco2013 Nov]No Change
    BZOJ1750: [Usaco2005 qua]Apple Catching
    BZOJ2733: [HNOI2012]永无乡
    BZOJ4756: [Usaco2017 Jan]Promotion Counting
    PHP 反射机制Reflection
    NOD 1113矩阵快速幂
    CODEVS 3500
    hdu 5172 GTY's gay friends 线段树
    LA 4329 Ping pong
    hdu 3500 DFS(限定)
  • 原文地址:https://www.cnblogs.com/huihuizhang/p/6904830.html
Copyright © 2011-2022 走看看