如何显示一个文本编辑框"在"屏幕? [英] How to show an text editing box "over" the screen?

查看:138
本文介绍了如何显示一个文本编辑框"在"屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有肖像的主要布局(它被固定为纵向)的应用程序,并且有一个地方提供了输入文本。我想推出类似的横向一个弹出窗口与背景图像雾了。我知道有一个弹出小工具,但任何想法旋转文本编辑框将是巨大的。旋转到一个纵向视图(文本框只)当键盘滑出也将工作,如将显示与键盘滑盖的文本框中输入新的屏幕。

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.

推荐答案

最简单的解决问题的方法是,以显示你的的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应该没有它的方向固定,因此它会旋转时滑出的键盘,你会期望。

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

创建文本输入活动

创建一个新的活动只的EditText查看含有和其他任何你想要包括(可能确定/取消按钮,也许标签?)。在清单中设置了主题 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"/>

雾化或模糊对话框后面的活动是通过修改的前景活动的窗口属性(文本输入对话框)完成。在它的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 启动文本输入活动。在这一活动的呼叫的setResult 返回使用<一个描述的技术返回的意图内输入的文本字符串href="http://stackoverflow.com/questions/449484/android-capturing-the-return-of-an-activity#449824">this帖子。

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 方法监听从子活动的结果。

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的开始。应注册侦听 keyboardHidden

android:configChanges="keyboardHidden"

在这一活动,覆盖 onConfigurationChanged 启动文本输入活动。

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);
}

您可能要检查确认键盘使用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.

这篇关于如何显示一个文本编辑框&QUOT;在&QUOT;屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆