views:

2905

answers:

2

If I have a application that has a primary layout of Portrait (It is fixed as portrait), but there is one place to type in text. I would like to launch like a popup window but in Landscape w/ the background image fogged out? I hope that makes sense. I know there is a Popup Widget, but any ideas to rotate the edittext box would be great. Thanks! Either that, or rotate it in a portate view (textbox only) when keyboard is slid out?

Thanks

On keyboard slide event, show new screen w/ edittext. ?

Chris.

+7  A: 

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.

Reto Meier
A: 

Once again, thank you for your insight.

Chrispix