标签:
1.添加样式
<style name="dialog_logout" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item> <!-- 边框 --> <item name="android:windowIsFloating">true</item> <!-- 是否浮现在activity之上 --> <item name="android:windowIsTranslucent">false</item> <!-- 半透明 --> <item name="android:windowNoTitle">true</item> <!-- 无标题 --> <item name="android:windowBackground">@color/transparent</item> <!-- 背景透明 --> <item name="android:backgroundDimEnabled">true</item> <!-- 模糊 --> <item name="android:windowAnimationStyle">@android:style/Animation.InputMethod</item> </style>2.添加需要的color
<resources> <color name="bg_gray">#FFEAEEF2</color> <color name="caribbean_green">#17D7B1</color> <color name="transparent">#00000000</color> <color name="white">#FFFFFFFF</color> <color name="red">#FFFF0000</color> <color name="text_dark">#FF333333</color> <color name="text_light">#FFACACAC</color> <color name="item_focus">#44ABABAB</color> <color name="list_deliver">#FFDDDDDD</color> <color name="bg_tr_dark">#22000000</color> </resources>3.布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="320dp" android:layout_height="wrap_content" android:background="@color/bg_gray" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="10dp" android:gravity="center" android:text="退出后不会删除任何历史数据,下次登录依然可以使用本账号" android:textSize="14sp" /> <Button android:id="@+id/dialog_btn_logout" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="20dp" android:background="@drawable/btn_warning_selector" android:text="退出登录" android:textColor="@color/white" android:textSize="20sp" /> <Button android:id="@+id/dialog_btn_cancel" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginBottom="35dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="20dp" android:background="@drawable/btn_gray_selector" android:text="取消" android:textColor="@color/white" android:textSize="20sp" /> </LinearLayout>
<pre name="code" class="java">public class DialogLogout extends Dialog { public DialogLogout(Context context) { super(context, R.style.dialog_logout); setCanceledOnTouchOutside(true); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_logout); Window window = getWindow(); LayoutParams params = window.getAttributes(); // 设置宽高 window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); // 设置弹出的动画效果 //window.setWindowAnimations(R.style.AnimBottom);//从底部滑出动画,自定义 // 设置监听 /* * (1)如果你需要设置x的值,那么需要将gravity设置有LEFT,START,RIGHT或者END。 * * (2)如果你需要设置y的值,那么需要将gravity设置成有TOP,BOTTOM。 */ params.gravity = Gravity.BOTTOM; //params.y = 0; window.setAttributes(params); findViewById(R.id.dialog_btn_cancel).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); } public void setClickLogoutListener(View.OnClickListener listener) { findViewById(R.id.dialog_btn_logout).setOnClickListener(listener); } }
final DialogLogout dialog = new DialogLogout(this); dialog.show(); dialog.setClickLogoutListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); //logout(); } });
标签:
原文地址:http://blog.csdn.net/gaobaoshen1/article/details/51364419