01.程式碼

01 Dialog dialog =newDialog(MenuShow.this,R.style.MyDialog);//指定自定義樣式
02 dialog.setContentView(R.layout.dialog);//指定自定義layout
03
04 //可自由調整佈局內部元件的屬性
05 LinearLayout ll = (LinearLayout)dialog.findViewById(R.id.lldialog);
06 ll.getLayoutParams().width=360;
07
08 Window dialogWindow = dialog.getWindow();
09 WindowManager.LayoutParams lp = dialogWindow.getAttributes();
10 //dialogWindow.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
11 lp.x = 500;// 新位置X坐標
12 lp.y = 450;// 新位置Y坐標
13 lp.width = 100;// 寬度
14 lp.height = 100;// 高度
15 lp.alpha = 0.7f;// 透明度
16
17 //新增自定義按鈕點擊監聽
18 Button btn = (Button)dialog.findViewById(R.id.dialog_button_ok);
19 btn.setOnClickListener(newOnClickListener() {
20
21 @Override
22 publicvoidonClick(View v) {
23
24 }
25 });
26
27 //顯示dialog
28 dialog.show();

02.styles.xml增加

1 <stylename="MyDialog"parent="@android:Theme.Dialog">
2 <itemname="android:windowFrame">@null</item>
3 <itemname="android:windowNoTitle">true</item>
4 <itemname="android:windowBackground">@drawable/dialog_full</item>
5 <itemname="android:windowIsFloating">true</item>
6 <itemname="android:windowContentOverlay">@null</item>
7 </style>

03.自定義layout

01 <?xmlversion="1.0"encoding="utf-8"?>
02 <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
03
04 android:orientation="vertical"
05 android:layout_width="wrap_content"
06 android:layout_height="wrap_content"
07 android:gravity="center_vertical|center_horizontal"
08 >
09
10 <LinearLayout
11 android:id="@+id/lldialog"
12 android:layout_width="match_parent"
13 android:layout_height="wrap_content"
14 android:orientation="vertical">
15
16 <LinearLayout
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">
23
24 <TextView
25 android:id="@+id/textView1"
26 android:layout_width="wrap_content"
27 android:layout_height="wrap_content"
28 android:layout_gravity="center_horizontal"
29 android:text="店名"/>
30
31 <TextView
32 android:id="@+id/textView2"
33 android:layout_width="wrap_content"
34 android:layout_height="wrap_content"
35 android:layout_gravity="center_horizontal"
36 android:text="地址"/>
37 </LinearLayout>
38
39 <LinearLayout
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">
46
47 <Button
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"
53 android:text="取消"
54 android:textColor="#FFFFFF"/>
55
56 <Button
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"
63 android:text="確定"
64 android:textColor="#FFFFFF"/>
65 </LinearLayout>
66
67 </LinearLayout>
68 </LinearLayout>

http://www.dotblogs.com.tw/superlm102/archive/2013/02/05/90118.aspx

更多相关文章

  1. android Dialog大小修改
  2. android用户界面-组件Widget-地图视图MapView
  3. Android(安卓)命令行编译、打包生成apk文件
  4. linearLayout 和 relativeLayout的属性区别
  5. 安卓(android)使用GPS,获取经纬度
  6. Android(安卓)MapView 申请apiKey
  7. android adb工具
  8. Android(安卓)MapView 申请apiKey
  9. android 命令(adb shell)进入指定模拟器或设备

随机推荐

  1. 手动操作Android数据库
  2. Android 打开指定文件夹
  3. android 在自己的程序中添加Widget
  4. Android之数据库操作
  5. Android Timer 实现方法
  6. android解压ZIP文件
  7. 获取Android各种系统信息
  8. 【实用工具】adb检测android设备
  9. Android Camera2 API 学习
  10. Android(安卓)最佳实践