设置样式
</style>
<style name="Theme_dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.6</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowAnimationStyle">@style/AnimationActivity</item>
</style>
<!-- 用于在一个框架内部,动态切换页面 -->
<style name="AnimationActivity" mce_bogus="1" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/dialog_enter</item><!-- 初进 ,100p到0-->
<item name="android:activityCloseExitAnimation">@anim/dialog_exit</item><!-- 关闭 ,0到100p-->
</style>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromYDelta="100%p"
android:toYDelta="0">
</translate>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromYDelta="0"
android:toYDelta="100%p">
</translate>
public class DialogActivity extends Activity implements OnClickListener {
private Button button_cancle;//取消按钮
private static int screenHeight;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Activity标题不显示
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏显示
setContentView(R.layout.activity_dialog);
init();
}
private void init(){
DisplayMetrics metri=new DisplayMetrics();
getWindow().getWindowManager().getDefaultDisplay().getMetrics(metri);
screenHeight=metri.heightPixels;
// screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight();//获取屏幕高度
WindowManager.LayoutParams lp = getWindow().getAttributes();lp包含了布局的很多信息,通过lp来设置对话框的布局
// lp.width = LayoutParams.FILL_PARENT;
lp.width =metri.widthPixels;
lp.gravity = Gravity.BOTTOM;
lp.height=screenHeight/2;//lp高度设置为屏幕的一半
getWindow().setAttributes(lp);//将设置好属性的lp应用到对话框
button_cancle=(Button) findViewById(R.id.button_cancle);
button_cancle.setOnClickListener(this);//取消按钮的点击事件监听
// button_cancle.setHeight(lp.height/6);//将button的高度设置为对话框的1/6
}