Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Show Dialogue Box at Clicked Place Without Dull Background in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 703
    Comment on it

    To attain such Dialogue box please go through the steps mentioned below:-

    1) Declare a button/ImageView in your Activity xml file, you can place this button on top right corner or left corner or in center wherever you wish you can place it. Here in this tutorial I'm placing the ImageView on left corner at top as shown below in xml file.

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:background="#CBCBCB">
    6.  
    7. <ImageView
    8. android:id="@+id/ivHamIcon"
    9. android:layout_width="wrap_content"
    10. android:layout_height="wrap_content"
    11. android:layout_alignParentBottom="true"
    12. android:layout_alignParentLeft="true"
    13. android:layout_below="@+id/ivCompanyLogo"
    14. android:layout_marginLeft="10dp"
    15. android:paddingTop="@dimen/ten"
    16. android:src="@drawable/hamburg" />
    17. </RelativeLayout>

    2) Now apply the setOnClick listener to the button/ImageView in your Activity java file. The setOnClickListener provides you the View with the help of which you can take out the x axis as well as the Y axis of the place where you performed the click on your Screen.

    1. ImageView ivHamIcon = (ImageView) findViewById(R.id.ivHamIcon);
    2. ivHamIcon.setOnClickListener(new View.OnClickListener() {
    3. @Override
    4. public void onClick(View view) {
    5.  
    6. int x = view.getLeft();
    7. int y = view.getBottom();
    8. hamburgerDialogue(x, y, BaseActivity.this, "Search");
    9. }
    10. });

    3) Now with the help of these X and Y axis we will place our dialogue box to appear near these axis by giving these axis at runtime.

    1. private void hamburgerDialogue(int x, int y, final Activity context, final String activity) {
    2.  
    3. final Dialog dialog = new Dialog(context);
    4. dialog.setCancelable(true);
    5. dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    6. dialog.setContentView(R.layout.hamburger_dialogue);
    7. dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    8. WindowManager.LayoutParams ll = dialog.getWindow().getAttributes();
    9. ll.gravity = Gravity.TOP | Gravity.LEFT;
    10. ll.x = 0;
    11. ll.y = y - 40;
    12. dialog.getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
    13. dialog.show();
    14. }

    haburger_dialogue.xml

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:orientation="vertical">
    6.  
    7. <LinearLayout
    8. android:layout_width="wrap_content"
    9. android:layout_height="wrap_content"
    10. android:background="#20365F"
    11. android:orientation="vertical">
    12.  
    13. <LinearLayout
    14. android:layout_width="match_parent"
    15. android:layout_height="match_parent"
    16. android:layout_marginEnd="@dimen/thirty_dpo"
    17. android:layout_marginStart="@dimen/ten"
    18. android:orientation="vertical">
    19.  
    20. <View
    21. android:layout_width="match_parent"
    22. android:layout_height="@dimen/one_dp"
    23. android:layout_marginBottom="@dimen/five"
    24. android:layout_marginTop="@dimen/five"
    25. android:background="#fff" />
    26.  
    27. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    28. android:id="@+id/tvHome"
    29. android:layout_width="match_parent"
    30. android:layout_height="wrap_content"
    31. android:layout_marginStart="@dimen/five"
    32. android:text="@string/home"
    33. android:textAllCaps="true"
    34. android:textColor="#fff" />
    35.  
    36. <View
    37. android:layout_width="match_parent"
    38. android:layout_height="@dimen/one_dp"
    39. android:layout_marginBottom="@dimen/five"
    40. android:layout_marginTop="@dimen/five"
    41. android:background="@android:color/white" />
    42.  
    43. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    44. android:id="@+id/tvUpcomingAuction"
    45. android:layout_width="wrap_content"
    46. android:layout_height="wrap_content"
    47. android:layout_marginStart="@dimen/five"
    48. android:text="@string/search"
    49. android:textAllCaps="true"
    50. android:textColor="@android:color/white" />
    51.  
    52. <View
    53. android:layout_width="match_parent"
    54. android:layout_height="1dp"
    55. android:layout_marginBottom="@dimen/five"
    56. android:layout_marginTop="@dimen/five"
    57. android:background="@android:color/white" />
    58.  
    59. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    60. android:id="@+id/tvBiddingOn"
    61. android:layout_width="wrap_content"
    62. android:layout_height="wrap_content"
    63. android:layout_marginStart="@dimen/five"
    64. android:textAllCaps="true"
    65. android:text="@string/search"
    66. android:textColor="@android:color/white" />
    67.  
    68. <View
    69. android:layout_width="match_parent"
    70. android:layout_height="1dp"
    71. android:layout_marginBottom="@dimen/five"
    72. android:layout_marginTop="@dimen/five"
    73. android:background="@android:color/white" />
    74.  
    75. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    76. android:id="@+id/tvItemsWatching"
    77. android:layout_width="match_parent"
    78. android:layout_height="wrap_content"
    79. android:layout_marginStart="@dimen/five"
    80. android:text="@string/search"
    81. android:textAllCaps="true"
    82. android:textColor="@android:color/white" />
    83.  
    84. <View
    85. android:layout_width="match_parent"
    86. android:layout_height="@dimen/one_dp"
    87. android:layout_marginBottom="@dimen/five"
    88. android:layout_marginTop="@dimen/five"
    89. android:background="@android:color/white" />
    90.  
    91. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    92. android:id="@+id/tvMyAccount"
    93. android:layout_width="match_parent"
    94. android:layout_height="wrap_content"
    95. android:layout_marginStart="@dimen/five"
    96. android:text="@string/search"
    97. android:textAllCaps="true"
    98. android:textColor="@android:color/white" />
    99.  
    100. <View
    101. android:layout_width="match_parent"
    102. android:layout_height="@dimen/one_dp"
    103. android:layout_marginBottom="@dimen/five"
    104. android:layout_marginTop="@dimen/five"
    105. android:background="@android:color/white" />
    106.  
    107. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    108. android:id="@+id/tvInformation"
    109. android:layout_width="match_parent"
    110. android:layout_height="wrap_content"
    111. android:layout_marginStart="@dimen/five"
    112. android:text="@string/search"
    113. android:textAllCaps="true"
    114. android:textColor="@android:color/white" />
    115.  
    116. <View
    117. android:layout_width="match_parent"
    118. android:layout_height="@dimen/one_dp"
    119. android:layout_marginBottom="@dimen/five"
    120. android:layout_marginTop="@dimen/five"
    121. android:background="@android:color/white" />
    122.  
    123. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    124. android:id="@+id/tvPreferences"
    125. android:layout_width="match_parent"
    126. android:layout_height="wrap_content"
    127. android:layout_marginStart="@dimen/five"
    128. android:text="@string/search"
    129. android:textAllCaps="true"
    130. android:textColor="@android:color/white" />
    131.  
    132. <View
    133. android:layout_width="match_parent"
    134. android:layout_height="@dimen/one_dp"
    135. android:layout_marginBottom="@dimen/five"
    136. android:layout_marginTop="@dimen/five"
    137. android:background="@android:color/white" />
    138.  
    139. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    140. android:id="@+id/tvChangePaswd"
    141. android:layout_width="match_parent"
    142. android:layout_height="wrap_content"
    143. android:layout_marginStart="@dimen/five"
    144. android:text="@string/search"
    145. android:textAllCaps="true"
    146. android:textColor="@android:color/white" />
    147.  
    148. <View
    149. android:layout_width="match_parent"
    150. android:layout_height="@dimen/one_dp"
    151. android:layout_marginBottom="@dimen/five"
    152. android:layout_marginTop="@dimen/five"
    153. android:background="@android:color/white" />
    154.  
    155. <com.kurtkaptein.android.kurt.fonts.Lucida_SansRegularTextView
    156. android:id="@+id/tvSearch"
    157. android:layout_width="match_parent"
    158. android:layout_height="wrap_content"
    159. android:layout_marginStart="@dimen/five"
    160. android:text="@string/search"
    161. android:textAllCaps="true"
    162. android:textColor="@android:color/white" />
    163.  
    164. <View
    165. android:layout_width="match_parent"
    166. android:layout_height="@dimen/one_dp"
    167. android:layout_marginBottom="@dimen/five"
    168. android:layout_marginTop="@dimen/five"
    169. android:background="@android:color/white" />
    170. </LinearLayout>
    171. </LinearLayout>
    172. </LinearLayout>
    173.  

    4) Now the last thing that we wish to do is that our background screen dose not go dim when our dialogue box appear for this we just need to clear a flag that do this here is the line of code for the same .

    1. dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: