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.
Share
The easiest solution to your problem is to display your
EditTextwithin a separatedialogthemed 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().setFlagsto apply blurring to any background Activities.Launching and Reading Entered Values from the Text Entry Activity
Use
startActivityForResultto launch the text entry Activity. Within that Activity callsetResultto return the text string entered within the returned intent using the techniques described in this post.Override the
onActivityResultmethod 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:configChangesattribute to the portrait Activity’s manifest entry. It should be registered to listen forkeyboardHidden.Within that Activity, override
onConfigurationChangedto 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.