一些自定义对话框收集:
底部弹出对话框的:
package com.djgzhiyong.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
private Button btnPopup;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnPopup = (Button) findViewById(R.id.btn);
btnPopup.setOnClickListener(this);
}
public void onClick(View v) {
showDialog();
}
private void showDialog() {
View view = getLayoutInflater().inflate(R.layout.photo_choose_dialog, null);
Dialog dialog = new Dialog(this, R.style.transparentFrameWindowStyle);
dialog.setContentView(view, new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
Window window = dialog.getWindow();
// 设置显示动画
window.setWindowAnimations(R.style.main_menu_animstyle);
WindowManager.LayoutParams wl = window.getAttributes();
wl.x = 0;
wl.y = getWindowManager().getDefaultDisplay().getHeight();
// 以下这两句是为了保证按钮可以水平满屏
wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
// 设置显示位置
dialog.onWindowAttributesChanged(wl);
// 设置点击外围解散
dialog.setCanceledOnTouchOutside(true);
dialog.show();
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="transparentFrameWindowStyle" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/photo_choose_bg</item>
</style>
<style name="main_menu_animstyle">
<item name="android:windowEnterAnimation">@anim/photo_dialog_in_anim</item>
<item name="android:windowExitAnimation">@anim/photo_dialog_out_anim</item>
</style>
</resources>
同时:
photo_dialog_in_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:fromYDelta="1000"
android:toXDelta="0"
android:toYDelta="0" />
</set>
photo_dialog_out_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="500"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="1000" />
</set>