Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:31:50+00:00 2026-06-12T15:31:50+00:00

I have an AlertDialog, whose Y is set and set to show on center.

  • 0

I have an AlertDialog, whose Y is set and set to show on center. It shows perfectly on 2.3 emulator & device, but on 4.1 (emulator & 4.0 device) it shows on more top than expected.
Here’s the code :

        AlertDialog adg = scrnDlg.create();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(adg.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    //lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    lp.y = 05;
    lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    adg.getWindow().setAttributes(lp);
                adg.show();
    /*  working with 2.3 but nt proper position with 4.0
        WindowManager.LayoutParams lp = adg.getWindow().getAttributes();
        lp.y = 05;
        lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
        adg.getWindow().setAttributes(lp);
        */

Screen shot of obth versions emulator :
enter image description here

Can any one help me wort out this problem ?
Also this height is perfect for Ld, Md. But for Hd & xD this height seems to be small & more space is left on bottom. How do I set the height based on screen height.

Any help ishighly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:31:51+00:00Added an answer on June 12, 2026 at 3:31 pm

    I finally got the above by setting the Gravity by testing the Android OS Version. This is how I did and get resutls as expected :

    alertDlg.show(); 
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(alertDlg.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.y = 02;
    if (MyActivity.Build_Version < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; 
    else if (MyActivity.Build_Version >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    lp.gravity = Gravity.CENTER_HORIZONTAL;
    
    alertDlg.getWindow().setAttributes(lp);
    

    Gravity of LayoutParams are treated differently by 4.1 and below 4.1 versions of the Android, thus the above is set and works perfectly.

    Hope this sharing help someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AlertDialog populated by an ExpandableListView. The list itself works perfectly, but
I have a translucent AlertDialog set to show if the user receives a text
I have one AlertDialog which is working fine.I have set some background images to
I have created an AlertDialog with OK button. But it is only displaying the
I have an activity whose only purpose is to launch an AlertDialog. My issue
I have created an AlertDialog using AlertDialog.Builder, but the Dialog border takes up too
I have a Custom AlertDialog.Builder but I couldn't reach the EditText. This is my
I have an AlertDialog having the text For more information, Please Call 1-800-200-1000 .
I have a custom AlertDialog where a user has to set password. There are
I have an AlertDialog appear whenever I find that the device location has changed.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.