Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了java – 将TextInput放在Android键盘上方而不绘制黑色矩形?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的 Android应用程序中,我有一个Activity,用户可以在其中添加一些文本到图像.按下启动此按钮的按钮时,屏幕底部会出现TexTinput,并显示“保存”按钮.

相关配置如下所示:

<activity
            android:name=".ImageEditOractivity"
 android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@String/title_activity_image_editor"
            android:parentActivityName=".MainActivity"
            android:windowSofTinputMode="adjustResize|stateHidden"
            android:theme="@style/FullscreenTheme">
            <Meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="myApp.MainActivity" />
        </activity>

活动xml看起来像这样 – 我已经修剪了几个与此功能无关的额外按钮:

<FrameLayout xmlns:android="http://scheR_207_11845@as.android.com/apk/res/android"
    xmlns:tools="http://scheR_207_11845@as.android.com/tools"
    xmlns:app="http://scheR_207_11845@as.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:BACkground="#0099cc"
    tools:context=".ImageEditOractivity"
    android:id="@+id/fullscreen_content">
<ScrollView
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_marginTop="50dp"
    android:isScrollContainer="true" >
        <RelativeLayout  xmlns:android="http://scheR_207_11845@as.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/edit_image"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:adjustViewBounds="true"></ImageView>
            <EditText
                android:id="@+id/image_comment"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginTop="8dp"
                android:paddingLeft="8dp"
                android:shadowDx="0"
                android:shadowDy="0"
                android:shadowRadius="2"
                android:hint="notes"
                android:text=""
                android:textColor="@android:color/black"
                android:BACkground="@android:color/white"
                android:layout_alignParentBottom="true"
                android:visibility="invisible"
                app:layout_consTraintStart_toEndOf="parent"
                app:layout_consTraintTop_toBottomOf="parent" />

            <Button
                android:id="@+id/image_comment_save_button"
                android:layout_width="100dp"
                android:layout_height="45dp"
                android:layout_marginBottom="2dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentright="true"
                android:text="Save"
                android:visibility="invisible"
                app:layout_consTraintStart_toEndOf="parent"
                app:layout_consTraintTop_toBottomOf="parent"
                />
        </RelativeLayout>
</ScrollView>
 <Button
            android:id="@+id/note_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@String/add_note"
            app:layout_consTraintBottom_toTopOf="parent"></Button>

活动以图像的路径开始,然后将其加载到图像中.按下音符按钮时,它会显示文本框.

noteButton.setOnClickListener(new View.onClickListener() {
        @Override
        public void onClick(View v) {
            writeNotes();
        }
    });

 private void writeNotes() {
        InputMethodManager methodMan = (InputMethodManager)getSystemservice(Context.INPUT_METHOD_serviCE);
        if (noteBox.getVisibility() == View.VISIBLE) {
            String text = noteBox.getText().toString();
            if ( 0 < text.trim().length() ) {
                Bitmap image = ((BitmapDrawablE) imageView.getDrawable()).getBitmap();
                writeOnImage(image,text);
                imageView.setImageBitmap(imagE);
                saveImage(image,lastTaken);
                exifData.put(ExifInterface.TAG_user_COMMENT,text);
            }
            noteBox.setVisibility(View.INVISIBLE);
            noteSaveButton.setVisibility(View.INVISIBLE);
            methodMan.hideSofTinputFromWindow(noteBox.getWindowToken(),0);
        }
        else {
            noteBox.setText("");
            noteBox.setVisibility(View.VISIBLE);
            noteSaveButton.setVisibility(View.VISIBLE);
            noteBox.requestFocus();
            methodMan.toggleSofTinput(InputMethodManager.SHOW_FORCED,0);
        }
    }

问题是当键盘打开时,它上面有一个大的黑色矩形,完全遮盖了EditText和Save按钮.这只发生在我的手机上,在7.1.1上,我试过的仿真器变体似乎正常工作.有趣的是,尽管它们被遮挡了,它们仍然可以工作 – 如果我在键盘上键入内容然后按下Save按钮的位置,它会按预期保存文本.

此屏幕截图显示了操作中的问题:

通过更改配置文件周围的设置,我发现没有显示黑色矩形的情况,但在每种情况下我都发现它也隐藏了EditText组件,即使在键盘关闭后我也再也看不到了,留下了活动在一个奇怪的状态,没有办法按下保存按钮.

如果键盘一直打开,只有在EditText具有焦点时才会出现黑色矩形,在此之前键盘看起来正常.

我在previous questions最接近的事情表明android:inputType =“textNoSuggestions”可能会有所帮助,但它似乎没有任何区别 – 这似乎不是一个建议框,只是一个任意的黑色矩形.

我需要做什么来阻止我的键盘在我的输入框上方绘制一个无意义的黑色矩形,或者如果我以某种方式接近错误的方式,我需要做一个允许用户看到的输入框我需要做什么他们正在写的文本,然后在内容完成时保存它?

解决方法

结果问题与屏幕底部的Android软件按钮有关,而不是键盘本身 – 由于某种原因,它们导致布局在键盘打开时不正确地测量屏幕.

解决方案是将android:fitsSystemWindows =“true”添加到视图根的FrameLayout.

大佬总结

以上是大佬教程为你收集整理的java – 将TextInput放在Android键盘上方而不绘制黑色矩形?全部内容,希望文章能够帮你解决java – 将TextInput放在Android键盘上方而不绘制黑色矩形?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。