Position of DialogFragment in Android
Try something like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
getDialog().getWindow().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
WindowManager.LayoutParams p = getDialog().getWindow().getAttributes();
p.width = ViewGroup.LayoutParams.MATCH_PARENT;
p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
p.x = 200;
...
getDialog().getWindow().setAttributes(p);
...
or other methods for getDialog().getWindow()
.
be sure to set the position after calling set-content.
DialogFragment Position in Android
There is fact a frame around it, that is defined in styles.xml, more specific it's the this 9-patch. The way i see it you have two options:
- Start playing around with negative top/left margin params until you align it exactly where you want it (watch out to use dpi values).
Apply the
DialogFragment.STYLE_NO_FRAME
like so:@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_FRAME, 0);
}
Dialogfragment positioning
First of all try setting:
params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
instead of
params.gravity = Gravity.BOTTOM | Gravity.CENTER;
Also, I think this is not really necessary:
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
since your style DialogFragment.STYLE_NO_FRAME
already disables TITLE
area.
If this doesn't help, pls paste your CustomDialog
style.
EDIT:
try changing your style to:
<style name="CustomDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/white</item>
<item name="android:background">@android:color/transparent</item>
</style>
How to get position of Item in Dialog fragment Android
You can use Bundle to send data between fragments. See link
In your FirstAlerDialogFragment
:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int itemPosition = position;
Bundle args = new Bundle();
args.putInt("position", itemPosition);
SecondAlertDialogFragment fragment = new SecondAlertDialogFragment;
fragment.setArguments(args);
fragment.show(getChildFragmentManager(), null);
}
And SecondAlertDialogFragment
:
Bundle args = getArguments();
int position = args.getInt("position");
switch (position) {
case 0:
phoneNumber = "12345";
email="mail.com";
break;
case 1:
phoneNumber = "1246";
email="mail2.com";
break;
case 2:
phoneNumber = "8780";
email="mail3.com";
break;
case 3:
phoneNumber = "123456";
email="mail4.com";
break;
}
Changing position of the Dialog on screen android
I used this code to show the dialog at the bottom of the screen:
Dialog dlg = <code to create custom dialog>;
Window window = dlg.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
This code also prevents android from dimming the background of the dialog, if you need it. You should be able to change the gravity parameter to move the dialog about
Related Topics
How to Draw a Circle with Animation in Android with Circle Size Based on a Value
How to Change the Toolbar Text Size
How to Perform a Fade Animation on Activity Transition
Dynamically Add Textviews to a Linearlayout
Android Spinner with Different Layouts for "Drop Down State" and "Closed State"
React Native Adb Reverse Enoent
How to Have a Gridview That Adapts Its Height When Items Are Added
Add Onclick Listener to Predefined Button
Android M Weird Shared Preferences Issue
Generate Barcode Image in Android Application
Asynctask: Where Does the Return Value of Doinbackground() Go
How to Use Android Canvas to Draw a Rectangle with Only Topleft and Topright Corners Round
Create Custom Big Notifications