Android自定义对话框
2024-07-14 16:13:58 227人阅读
01.程式碼
01 | Dialog dialog = new Dialog(MenuShow. this ,R.style.MyDialog); |
02 | dialog.setContentView(R.layout.dialog); |
05 | LinearLayout ll = (LinearLayout)dialog.findViewById(R.id.lldialog); |
06 | ll.getLayoutParams().width=360; |
08 | Window dialogWindow = dialog.getWindow(); |
09 | WindowManager.LayoutParams lp = dialogWindow.getAttributes(); |
18 | Button btn = (Button)dialog.findViewById(R.id.dialog_button_ok); |
19 | btn.setOnClickListener( new OnClickListener() { |
22 | public void onClick(View v) { |
02.styles.xml增加
1 | < style name = "MyDialog" parent = "@android:Theme.Dialog" > |
2 | < item name = "android:windowFrame" >@null</ item > |
3 | < item name = "android:windowNoTitle" >true</ item > |
4 | < item name = "android:windowBackground" >@drawable/dialog_full</ item > |
5 | < item name = "android:windowIsFloating" >true</ item > |
6 | < item name = "android:windowContentOverlay" >@null</ item > |
03.自定義layout
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
02 | < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" |
04 | android:orientation = "vertical" |
05 | android:layout_width = "wrap_content" |
06 | android:layout_height = "wrap_content" |
07 | android:gravity = "center_vertical|center_horizontal" |
11 | android:id = "@+id/lldialog" |
12 | android:layout_width = "match_parent" |
13 | android:layout_height = "wrap_content" |
14 | android:orientation = "vertical" > |
17 | android:layout_width = "match_parent" |
18 | android:layout_height = "wrap_content" |
19 | android:background = "@drawable/dialog_up" |
20 | android:orientation = "vertical" |
21 | android:paddingBottom = "10dp" |
22 | android:paddingTop = "10dp" > |
25 | android:id = "@+id/textView1" |
26 | android:layout_width = "wrap_content" |
27 | android:layout_height = "wrap_content" |
28 | android:layout_gravity = "center_horizontal" |
32 | android:id = "@+id/textView2" |
33 | android:layout_width = "wrap_content" |
34 | android:layout_height = "wrap_content" |
35 | android:layout_gravity = "center_horizontal" |
40 | android:layout_width = "match_parent" |
41 | android:layout_height = "wrap_content" |
42 | android:background = "@drawable/dialog_dn" |
43 | android:gravity = "center" |
44 | android:padding = "10dp" |
45 | android:paddingBottom = "10dp" > |
48 | android:id = "@+id/dialog_button_cancel" |
49 | android:layout_width = "0dp" |
50 | android:layout_height = "51dip" |
51 | android:layout_weight = "1" |
52 | android:background = "@drawable/btn_bg_gray" |
54 | android:textColor = "#FFFFFF" /> |
57 | android:id = "@+id/dialog_button_ok" |
58 | android:layout_width = "0dp" |
59 | android:layout_height = "51dp" |
60 | android:layout_marginLeft = "10dp" |
61 | android:layout_weight = "1" |
62 | android:background = "@drawable/btn_bg_green" |
64 | android:textColor = "#FFFFFF" /> |
http://www.dotblogs.com.tw/superlm102/archive/2013/02/05/90118.aspx
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。