Android之底部弹窗对话框

版权声明:本文为博主原创文章,未经博主允许不的转载。谢谢! https://blog.csdn.net/niu9799/article/details/80887694

Android之底部弹窗对话框

说到底部弹窗突然想到几年前做运动轨迹时轨迹记录可以从底部弹窗选择相对时间的轨迹,那时候用的popwindow。

老规矩先上效果图:


核心代码

		final Dialog dialog = new Dialog(this, R.style.BottomDialogStyle);
		View view = View.inflate(this, R.layout.view_bottomdialog, null);
		Button mCancel = (Button) view.findViewById(R.id.cancel_bt);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(true);
		view.setMinimumHeight((int) (ScreenSizeUtils.getInstance(this).getScreenHeight() * 0.23f));
		Window dialogWindow = dialog.getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = (int) (ScreenSizeUtils.getInstance(this).getScreenWidth());
		lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
		lp.gravity = Gravity.BOTTOM;
		dialogWindow.setAttributes(lp);
		mCancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dialog.dismiss();

			}
		});
		dialog.show();

Style

    <style name="BottomDialogStyle">
        <!-- 对话框背景 -->
        <item name="android:windowBackground">@android:color/transparent</item>
        <!-- 边框 -->
        <item name="android:windowFrame">@null</item>
        <!-- 没有标题 -->
        <item name="android:windowNoTitle">true</item>
        <!-- 是否浮现在Activity之上 -->
        <item name="android:windowIsFloating">true</item>
        <!-- 背景透明 -->
        <item name="android:windowIsTranslucent">false</item>
        <!-- 是否有覆盖 -->
        <item name="android:windowContentOverlay">@null</item>
        <!-- 进出的显示动画 -->
        <item name="android:windowAnimationStyle">@style/bottomDialogAnim</item>
        <!-- 背景变暗 -->
        <item name="android:backgroundDimEnabled">true</item>
    </style>
    <!-- 动画 -->
    <style name="bottomDialogAnim" parent="android:Animation">
        <item name="@android:windowEnterAnimation">@anim/dialog_enter_anim</item>
        <item name="@android:windowExitAnimation">@anim/dialog_exit_anim</item>
    </style>

布局文件

view_bottomdialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:orientation="vertical" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:text="拍照" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#FFD700" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:text="相册" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#FFD700" />

    <Button
        android:id="@+id/cancel_bt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:text="取消" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#FFD700" />

</LinearLayout>

猜你喜欢

转载自blog.csdn.net/niu9799/article/details/80887694