当我在键盘上输入任何东西,然后谷歌打开。无法在此EditText视图中键入内容。在这里,我创建了覆盖服务。这里我写了强制打开软键盘逻辑的代码。www.example.com floatingPointWidthService.java
public void onCreate() {
super.onCreate();
//init WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
getWindowManagerDefaultDisplay();
//Init LayoutInflater
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
addRemoveView(inflater);
addFloatingWidgetView(inflater);
implementClickListeners();
implementTouchListenerToFloatingWidgetView();
System.out.println("mFloatingWidgetView" +mFloatingWidgetView);
expandedView = mFloatingWidgetView.findViewById(R.id.expanded_container);
expandedView.setVisibility(View.VISIBLE);//set large view open
edittext1 = mFloatingWidgetView.findViewById(R.id.floating_widget_title_label);
edittext1.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(edittext1.getApplicationWindowToken(), 1);
imm.showSoftInput(edittext1, InputMethodManager.SHOW_IMPLICIT);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
这里我有修改android:windowSoftInputMode="adjustPan"
AndroidManifest.xml
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ModFill"
tools:targetApi="31"
android:windowSoftInputMode="adjustPan"// this is for overlayKeyBoard
>
这是覆盖模式的布局,我在这里添加了EditText。floating_width_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Root container of Floating Widget View -->
<RelativeLayout
android:id="@+id/root_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- View while view is collapsed -->
<RelativeLayout
android:id="@+id/collapse_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<!-- ImageView of floating widget -->
<ImageView
android:id="@+id/collapsed_iv"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginTop="8dp"
android:src="@mipmap/ic_launcher_round"
tools:ignore="ContentDescription" />
<!-- Close button to close Floating Widget View -->
<ImageView
android:id="@+id/close_floating_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="5dp"
android:background="@drawable/circle_shape"
android:src="@drawable/ic_close_white_24dp"
tools:ignore="ContentDescription" />
</RelativeLayout>
<!-- View while view is expanded -->
<LinearLayout
android:id="@+id/expanded_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:gravity="center"
android:orientation="horizontal"
android:padding="8dp"
android:visibility="gone">
<ImageView
android:id="@+id/floating_widget_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<EditText
android:id="@+id/floating_widget_title_label"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:hint="Enter your comment"
android:textColor="@android:color/black"
android:textSize="14sp" />
</LinearLayout>
<!-- ImageView to Close Expanded View -->
<ImageView
android:id="@+id/close_expanded_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:src="@drawable/ic_close_black_24dp" />
<!-- ImageView to Open Activity -->
<ImageView
android:id="@+id/open_activity_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:src="@drawable/ic_aspect_ratio_black_24dp" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
键盘正在使用最后一行imm.toggleSoftInput
方法打开。请告诉如何在此EditText中键入文本。
1条答案
按热度按时间vc6uscn91#
你不需要这些。设定焦点就足够了。特别是这里的第2行和第4行是错误的--它们都将显示键盘,但没有将其正确地连接到InputConnection,从而导致键盘出现但什么也不做。