我有一个应用程序,其主要布局为纵向(固定为纵向),并且有一个地方可以输入文本.我想像一个横向的弹出窗口一样启动,背景图像模糊不清.我知道有一个弹出窗口小部件,但任何旋转文本编辑框的想法都会很棒.滑出键盘时将其旋转到纵向视图(仅限文本框)也可以,就像在键盘滑动上显示带有文本框的新屏幕一样.
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.
解决问题的最简单方法是在一个单独的 dialog
主题 Activity 中显示您的 EditText
从您的主要(纵向固定)活动中启动.
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.
EditText Activity 的方向不应固定,因此当您滑出键盘时它会按预期旋转.
The EditText Activity shouldn't have its orientation fixed, so it will rotate as you'd expect when you slide out the keyboard.
创建文本输入活动
创建一个新的 Activity,它只包含 EditText 视图和您想要包含的任何其他内容(可能是 OK/Cancel 按钮,也可能是一个标签?).在清单中将其主题设置为 Theme.Dialog
.
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"/>
通过修改前台 Activity(您的文本输入对话框)的 Window 属性来对对话框后面的 Activity 进行模糊或模糊处理.在它的 onCreate 方法中,使用 getWindow().setFlags
将模糊应用于任何背景活动.
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);
从文本输入活动中启动和读取输入的值
使用 startActivityForResult
启动文本输入 Activity.在该活动中调用 setResult
以使用 这篇文章.
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.
重写 onActivityResult
方法以监听子 Activity 的结果.
Override the onActivityResult
method to listen for the result from the sub Activity.
在暴露的键盘上触发启动
您可以随时启动文本输入活动,但如果您希望在键盘暴露时始终显示它,您可以显式捕获此事件.
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.
首先将 android:configChanges
属性添加到肖像 Activity 的清单条目中.它应该被注册以监听 keyboardHidden
.
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"
在该 Activity 中,覆盖 onConfigurationChanged
以启动文本输入 Activity.
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);
}
在启动文本输入 Activity 之前,您可能需要使用 newConfig 变量检查确认键盘是否被暴露(而不是隐藏).
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.
这篇关于如何显示文本编辑框“over"屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!