如何在“上方”显示文本编辑框 屏幕?

发布于 2024-07-11 10:59:02 字数 157 浏览 4 评论 0 原文

我有一个应用程序,其主要布局为纵向(它固定为纵向),并且有一个地方可以输入文本。 我想像横向弹出窗口一样启动,背景图像模糊。 我知道有一个弹出窗口小部件,但是任何旋转文本编辑框的想法都会很棒。 当键盘滑出时,将其旋转为纵向视图(仅限文本框)也可以,就像在键盘幻灯片上显示带有文本框的新屏幕一样。

I have an application that has a primary layout of portrait (it is fixed as portrait), and there is one place to type in text. I would like to launch like a popup window in landscape orientation with the background image fogged out. I know there is a Popup Widget, but any ideas for rotating the text edit box would be great. Rotating it into a portrait view (text box only) when the keyboard is slid out would also work, as would showing a new screen with the text box on keyboard slide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2024-07-18 10:59:02

解决您的问题的最简单的方法是在单独的 dialog 主题 Activity 中显示您的 EditText,该 Activity 是您从主(纵向固定)Activity 中启动的。

EditText Activity 的方向不应该固定,因此当您滑出键盘时它会按照您的预期旋转。

创建文本输入活动

创建一个新活动,其中仅包含 EditText 视图和您想要包含的任何其他内容(可能是“确定”/“取消”按钮,也可能是一个标签?)。 在清单中将其主题设置为 Theme.Dialog

<activity android:name="TextEntryActivity" 
          android:label="My Activity" 
          android:theme="@android:style/Theme.Dialog"/>

通过修改前台活动(文本输入对话框)的窗口属性来对对话框后面的活动进行雾化或模糊化。 在其 onCreate 方法中,使用 getWindow().setFlags 将模糊应用于任何背景 Activity。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,  
                     WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

启动文本输入 Activity 并读取输入的值

使用 startActivityForResult 启动文本输入 Activity。 在该 Activity 中,调用 setResult 以使用 这篇文章

重写 onActivityResult 方法以侦听子 Activity 的结果。

在键盘暴露时触发启动

您可以随时启动文本输入 Activity,但如果您希望在键盘暴露时始终显示它,则可以显式捕获此事件。

首先将 android:configChanges 属性添加到纵向 Activity 的清单条目中。 应该注册它来侦听keyboardHidden

android:configChanges="keyboardHidden"

在该 Activity 中,重写 onConfigurationChanged 以启动文本输入 Activity。

@Override
public void onConfigurationChanged(Configuration newConfig) {  
  Intent i = new Intent(this,TextEntryActivity.class);    
  startActivityForResult(i, STATIC_INTEGER_VALUE);
}

在启动文本输入活动之前,您可能需要使用 newConfig 变量进行检查以确认键盘是否已公开(而不是隐藏)。

您可能还想使用相同的技术在键盘隐藏时自动从文本输入活动返回。

The easiest solution to your problem is to display your EditText within a separate dialog themed Activity that you launch from within your main (portrait-fixed) Activity.

The EditText Activity shouldn't have its orientation fixed, so it will rotate as you'd expect when you slide out the keyboard.

Creating the Text Entry Activity

Create a new Activity the contains only the EditText View and anything else you want to include (probably OK / Cancel buttons and maybe a label?). Within the manifest set its theme to Theme.Dialog.

<activity android:name="TextEntryActivity" 
          android:label="My Activity" 
          android:theme="@android:style/Theme.Dialog"/>

Fogging or Blurring the Activities behind a dialog is done by modifying the Window properties of the foreground Activity (your text entry dialog). Within it's onCreate method use getWindow().setFlags to apply blurring to any background Activities.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,  
                     WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

Launching and Reading Entered Values from the Text Entry Activity

Use startActivityForResult to launch the text entry Activity. Within that Activity call setResult to return the text string entered within the returned intent using the techniques described in this post.

Override the onActivityResult method to listen for the result from the sub Activity.

Triggering Launch on Keyboard Exposed

You can launch the text entry Activity whenever you want, but if you want to always display it when the keyboard is exposed you can capture this event explicitely.

Start by adding the android:configChanges attribute to the portrait Activity's manifest entry. It should be registered to listen for keyboardHidden.

android:configChanges="keyboardHidden"

Within that Activity, override onConfigurationChanged to launch the text entry Activity.

@Override
public void onConfigurationChanged(Configuration newConfig) {  
  Intent i = new Intent(this,TextEntryActivity.class);    
  startActivityForResult(i, STATIC_INTEGER_VALUE);
}

You may want to check to confirm the keyboard is being exposed (rather than hidden) using the newConfig variable before launching the text entry Activity.

You may also want to use the same technique to automatically return from the text entry activity when the keyboard is hidden.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文