Whatsapp附件的窗口如何覆盖键盘?

时间:2017-07-05 12:10:00

标签: android

我正在研究一个类似的问题来开发我的聊天,我正在检查whatsapp如何解决它以获得一个想法来处理它。

在移动设备和对话内,当您的键盘在屏幕上并且您点击附件时,附件窗口将覆盖键盘,如下图所示。它也看起来像它下面的活动冻结(你可以看看EditText上的斜杠“|”,它似乎是冻结)。

我想知道WP如何覆盖键盘以及为什么看起来它下面的活动是冻结的,提前感谢!

enter image description here

1 个答案:

答案 0 :(得分:1)

enter image description here / 使用以下代码Snipet而不使用任何库 /

   action_attach.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openDialog();
        }
    });


  private void openDialog() {
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // inflate the custom popup layout
    final View inflatedView;

    inflatedView = layoutInflater.inflate(R.layout.custom_dialog_options_menu, null, false);

    LinearLayout layoutGallery;
   layoutGallery = (LinearLayout) inflatedView.findViewById(R.id.layoutGallery);
    layoutGallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            FloatingView.dismissWindow();
        }
    });

    FloatingView.onShowPopup(this, inflatedView);
  }



 /**Sample Layout for Pop Up window ie: custom_dialog_options_menu
    and change layout according to your choice***/


 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:paddingTop="82dp">

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

    <LinearLayout
        android:id="@+id/layoutGallery"
        android:layout_width="0dp"
        android:layout_marginTop="18dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/gallery_attach_icon_selector"/>

        <TextView
            android:id="@+id/tvGallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Gallery"
            android:layout_marginTop="10dp"
            android:textSize="16sp"
            android:textColor="#4d4747"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutPhoto"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginTop="18dp"
        android:orientation="vertical">

        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/camera_attach_icon_selector"/>

        <TextView
            android:id="@+id/tvPhoto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Camera"
            android:layout_marginTop="10dp"
            android:textSize="16sp"
            android:textColor="#4d4747"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutVideo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="40dp"
        android:layout_weight="1"
        android:layout_marginTop="18dp"
        android:orientation="vertical">

        <ImageView
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/video_attach_icon_selector"/>

        <TextView
            android:id="@+id/tvVideo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="Video"
            android:layout_marginTop="10dp"
            android:textSize="16sp"
            android:textColor="#4d4747"/>

    </LinearLayout>

</LinearLayout>

</LinearLayout>


/**FloatingView Class**/

public class FloatingView
{
/* Floating view is used to display a custom view for attachments in the chat screen */

import android.app.Activity;
import android.graphics.Point;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

private static PopupWindow popWindow;

private FloatingView() {
}


public static void onShowPopup(Activity activity, View inflatedView) {

    // get device size
    Display display = activity.getWindowManager().getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);
    // fill the data to the list items
    // set height depends on the device size
    popWindow = new PopupWindow(inflatedView, size.x, ViewGroup.LayoutParams.WRAP_CONTENT,
            true);
    // set a background drawable with rounders corners
    popWindow.setBackgroundDrawable(activity.getResources().getDrawable(
            R.drawable.comment_popup_bg));
    // make it focusable to show the keyboard to enter in `EditText`
    popWindow.setFocusable(true);
    // make it outside touchable to dismiss the popup window
    popWindow.setOutsideTouchable(true);

    popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    // show the popup at bottom of the screen and set some margin at
    // bottom ie,

    popWindow.showAtLocation(activity.getCurrentFocus(), Gravity.BOTTOM, 0,
            0);
}

public static void dismissWindow() {

    popWindow.dismiss();
}