Bonjour,
Je développe une application en ce moment mais j'ai un problème pour afficher correctement une fenêtre popup.
Si jamais vous avez une solution ce serait super.
Voici ce que ça doit donner et ce que ça donne sur l'interface graphique de android studio :
Et ce que ça donne sur mon portable :
Voici le code du xml de la popup :
Voici le code de la classe main_activity :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="100dp" android:layout_gravity="bottom" android:background="@color/bluelight" android:fitsSystemWindows="false" android:orientation="vertical" android:padding="15dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:baselineAligned="false" android:orientation="horizontal"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="horizontal"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:foregroundGravity="top" android:gravity="top|left" android:text="@string/menu" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="right" android:orientation="horizontal"> <TextView android:id="@+id/txtclose" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="end" android:background="@drawable/cerclebackground" android:gravity="center" android:text="X" android:textColor="@color/white" android:textStyle="bold" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:baselineAligned="false" android:gravity="center" android:orientation="horizontal"> <ImageView android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|center" android:layout_marginTop="1dp" android:src="@drawable/ic_action_name" /> </LinearLayout> </LinearLayout>
puis le code du xml du main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public class MainActivity extends AppCompatActivity { Dialog myDialog; private ImageView imagebutton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myDialog = new Dialog(this); } public void ShowPopup (View v){ TextView txtclose; ImageView btn1; myDialog.setContentView(R.layout.menu_popup); txtclose = (TextView) myDialog.findViewById(R.id.txtclose); btn1 = (ImageView) myDialog.findViewById(R.id.btn1); txtclose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myDialog.dismiss(); } }); myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); myDialog.show(); } }
Merci ^^
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:background="@color/bluedark" android:fitsSystemWindows="false" android:gravity="top|center" android:orientation="vertical" android:paddingTop="10dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|center" android:background="@drawable/buttonstyle" android:gravity="top|center" android:onClick="ShowPopup" android:text="show popup" android:textColor="@color/white" /> </LinearLayout>
Partager