gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:28:31 24 4
gpt4 key购买 nike

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

在移动设备和对话中,当您的键盘在屏幕上打开并单击附件时,附件窗口会覆盖键盘,如下图所示。它也看起来像它下面的 Activity 卡住了(你可以看看 EditText 上的斜杠“|”,它似乎是卡住的)。

我想知道 WP 如何覆盖键盘以及为什么它下面的 Activity 看起来像卡住,在此先感谢!

enter image description here

最佳答案

enter image description here/在不使用任何库的情况下使用下面的代码 fragment /

   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();
}

关于android - Whatsapp 附件的窗口如何覆盖键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44925893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com