I am using a custom dialog in my activity. I want to set the screen orientation only if the dialog is shown elsewhere the screen orientation can change to portrait to landscape vice versa. Is there any way to fix the orientation for such particular case specifically in java code.
We had to do this in a fullscreen dialog launched from a service.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
params.copyFrom(window.getAttributes());
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
window.setAttributes(params);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//Show dialog here
//...
//Hide dialog here
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
use android:configChanges="orientation" then Android doesn't re-create the activity when the orientation is changed. If you don't want the dialog to be dismissed, just use the Activity.showDialog() method. And if you still want to use android:configChanges="orientation" then you have to change drawables manually in the Activity.onConfigurationChanged() method.
Related
When I set a dialog in full screen it isn't really fullscreen.
see here
How can I fix that?
Window window = getWindow();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
This code is in a custom dialog class that extends Dialog.
That's why I am able to write only getWindow().
Actually I don't need it to be fullscreen but I need atleast the pixel difference between the screen and the dialog box.
you can add the following theme to dialog's second parameter android.R.style.Theme_Black_NoTitleBar_Fullscreen
Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen)
I have a DialogFragment with two EditText fields and another field with an ImageView to increment its value underneath these, they all live in a ScrollView.
The problem is neither adjust mode for the soft keyboard shows my entire DialogFragment at once, despite there being space.
adjustResize causes the ScrollView to resize and hide the bottom row. adjustpan keeps the ScrollView size intact but the soft keyboard overlaps the bottom row.
Removing the ScrollView means either option causes the keyboard to overlap.
What I would like is for the DialogFragment to move up the screen without resizing. Can I make that happen? Ideally I'd like to keep the ScrollView in my Layout to better support very small screens.
The only solution I found was to change the window options for the dialog fragment itself. Obviously on a smaller screen this will still be an issue so I am still looking for a better answer.
#Override
#NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
//I was using android.R.style.Theme_Translucent_NoTitleBar for another issue
//but I don't think the theme makes any difference to how the window is laid out
//that is relevant to the below code
Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent_NoTitleBar);
... //Do your usual stuff here
dialog.getWindow().setContentView(...);
final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.TOP; //this is the important part
dialog.setCanceledOnTouchOutside(false);
return dialog;
}
I wish to create a activity that look like a popup window
That is with transparent background for activity als i wish to show it in custom position on scree that is on right corner of device screen
what i did was inside onCreate of pop over like activty
Display display = getWindow().getWindowManager().getDefaultDisplay();
WindowManager.LayoutParams params = getWindow().getAttributes();
// params.x = -20;
params.height = (display.getHeight()) / 2;
params.width = (display.getWidth()) / 2;
// params.y = -10;
params.gravity = Gravity.RIGHT;
getWindow().setAttributes(params);
in maifest
<activity android:name=".DialogAct"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"></activity>
This is what my launcher activity looks like
So when i click on search on action bar i'm sending intent to my new activity .I want to make it look like pop just below the search icon
This what i obtained is
You can see search of previous activity is clicked and new activity is loaded(blue portion).
As you can see the new activity moves to centre of screen . but i want it just below the action bar icon.
i tried params.gravity = Gravity.TOP | Gravity.RIGHT;. then i got this
I want to place it just below the action bar of previous activity . I tried many ways to achieve it but failed. so can anyone suggest a methode
In your manifest you wrote
<activity android:name=".DialogAct"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
you should remove the NoActionBar part
<activity android:name=".DialogAct"
android:theme="#android:style/Theme.Holo.Light">
I can think of two things that may help. First, you could try changing the Theme in your manifest to android:theme="#android:style/Theme.Dialog and this should give you the wanted look.
Edit
You can hide the title bar with
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
just make sure to call it before calling setContentView()
Also, if it doesn't need to be a separate Activity you could use PopupWindow. With this you can use isAboveAnchor and use the ActionBar as the anchor and place it below or use one of the other associated methods. I don't know if either of these will fulfill what you need but they may work for you.
#edwin What you can do is after making
params.gravity = Gravity.TOP | Gravity.RIGHT;
you just provide some margin from top, like this:
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
yourCustomPopOveractivity.setLayoutParams(params);
and i think after doing this you can get your needed position and everything you just did is right.
Please try then tell me
Try Gravity to Center rather than Top Right..
Is there any possibility in Android to align a dialog Activity (activity with a dialog theme) at the bottom? By default, it is displayed in the middle of the screen. I haven't found any information on that... Thanks.
This is not exactly what you are doing, but I had a similar problem where I needed to display a dialog from an activity - at the bottom of the screen. The trick was to use WindowManager.LayoutParams. Here's what my onPrepareDialog looks like:
public void onPrepareDialog(int dialog, Dialog dlg) {
Window window = dlg.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
switch (dialog) {
case DIALOGUE_LOADING_PLEASE_WAIT:
wlp.gravity = Gravity.BOTTOM;
window.setAttributes(wlp);
break;
default:
break;
}
}
I didn't tried but searching on google found this...does this help you getWindow().setAttributes() , I hope this will help you.
content of the link (if it doesn't work) :-
You can call getWindow().getAttributes() to retrieve the
WindowManager.LayoutParams for the window. This has the following
fields involving window placement:
http://code.google.com/android/reference/android/view/ViewGroup.LayoutParams.html#width
http://code.google.com/android/reference/android/view/ViewGroup.LayoutParams.html#height
http://code.google.com/android/reference/android/view/WindowManager.LayoutParams.html#gravity
http://code.google.com/android/reference/android/view/WindowManager.LayoutParams.html#x
http://code.google.com/android/reference/android/view/WindowManager.LayoutParams.html#y
After making your desired changes, use getWindow().setAttributes() to
install the new values.
Note that, though you can force a specific size through the width and
height fields, in general the correct way to do this is let the window
do its normal layout and determine the window size automatically that
way. If you have a single view in the dialog that wants a fixed size
such as 300x200, implement View.onMeasure() to call
setMeasuredDimension(300, 200). Then when the view hierarchy layout
happens, the dialog window will be given a size that ensures your view
is that dimension (probably making the actual window larger to take
into account the dialog frame and decoration).
http://code.google.com/android/reference/android/view/View.html#onMeasure(int,%20int)
I'd like to show a Dialog that occupies as much screen space as possible.
So, here's a sample:
AlertDialog dialog = new AlertDialog.Builder(ctx)......create();
Window w = dialog.getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
lp.width = 320;
lp.height = 480;
w.setAttributes(lp);
Problem is, this doesn't change a thing. Why?
TIA.
I don't know how to do exactly what you're wanting, but isn't this mostly defeating the purpose of a Dialog? Why not just create a custom Activity and use the Dialog theme if you're just wanting it to look dialog-ey.
You need to change the window layout parameters AFTER setContentView. Anything you do to the window before then (size/location-wise) will be tossed out when you call setContentView.
http://devstream.stefanklumpp.com/2010/07/android-display-dialogs-in-fullscreen.html
You need to add minWidth and minHeight attributes in the Dialog's xml layout file. E.g. your screen size is 800 * 480, then set android:minWidth="800dip", android:minHeight="400dip"