Android Whatsapp附件的窗口如何覆盖键盘?
我正在处理一个类似的问题来开发我的聊天,我正在检查whatsapp是如何解决这个问题的,以获得解决这个问题的想法 在手机和对话中,当键盘在屏幕上并单击附件时,“附件”窗口将覆盖keboard,如下图所示。它看起来也像是它下面的活动冻结了。你可以看看EditText上的斜线,看起来是冻结 我想知道WP是如何覆盖键盘的,为什么它下面的活动看起来像是冻结的,提前谢谢 /在不使用任何库的情况下使用以下代码Snipet/Android Whatsapp附件的窗口如何覆盖键盘?,android,Android,我正在处理一个类似的问题来开发我的聊天,我正在检查whatsapp是如何解决这个问题的,以获得解决这个问题的想法 在手机和对话中,当键盘在屏幕上并单击附件时,“附件”窗口将覆盖keboard,如下图所示。它看起来也像是它下面的活动冻结了。你可以看看EditText上的斜线,看起来是冻结 我想知道WP是如何覆盖键盘的,为什么它下面的活动看起来像是冻结的,提前谢谢 /在不使用任何库的情况下使用以下代码Snipet/ 您可以使用BottomSheetDialog执行以下操作:示例:哇,好人,似乎是正确
您可以使用BottomSheetDialog执行以下操作:示例:哇,好人,似乎是正确的答案!!真是太阳穴了!
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();
}