我有一个应用程序,其主要布局为纵向(它固定为纵向),并且有一个地方可以输入文本。 我想像横向弹出窗口一样启动,背景图像模糊。 我知道有一个弹出窗口小部件,但是任何旋转文本编辑框的想法都会很棒。 当键盘滑出时,将其旋转为纵向视图(仅限文本框)也可以,就像在键盘幻灯片上显示带有文本框的新屏幕一样。
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.
发布评论
评论(1)
解决您的问题的最简单的方法是在单独的
dialog
主题 Activity 中显示您的EditText
,该 Activity 是您从主(纵向固定)Activity 中启动的。EditText Activity 的方向不应该固定,因此当您滑出键盘时它会按照您的预期旋转。
创建文本输入活动
创建一个新活动,其中仅包含 EditText 视图和您想要包含的任何其他内容(可能是“确定”/“取消”按钮,也可能是一个标签?)。 在清单中将其主题设置为
Theme.Dialog
。通过修改前台活动(文本输入对话框)的窗口属性来对对话框后面的活动进行雾化或模糊化。 在其 onCreate 方法中,使用 getWindow().setFlags 将模糊应用于任何背景 Activity。
启动文本输入 Activity 并读取输入的值
使用
startActivityForResult
启动文本输入 Activity。 在该 Activity 中,调用setResult
以使用 这篇文章。重写
onActivityResult
方法以侦听子 Activity 的结果。在键盘暴露时触发启动
您可以随时启动文本输入 Activity,但如果您希望在键盘暴露时始终显示它,则可以显式捕获此事件。
首先将
android:configChanges
属性添加到纵向 Activity 的清单条目中。 应该注册它来侦听keyboardHidden
。在该 Activity 中,重写
onConfigurationChanged
以启动文本输入 Activity。在启动文本输入活动之前,您可能需要使用 newConfig 变量进行检查以确认键盘是否已公开(而不是隐藏)。
您可能还想使用相同的技术在键盘隐藏时自动从文本输入活动返回。
The easiest solution to your problem is to display your
EditText
within a separatedialog
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
.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.Launching and Reading Entered Values from the Text Entry Activity
Use
startActivityForResult
to launch the text entry Activity. Within that Activity callsetResult
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 forkeyboardHidden
.Within that Activity, override
onConfigurationChanged
to launch the text entry Activity.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.