Android编程入门--底部Dialog弹窗

参考博客:Android实现底部对话框BottomDialog

dialog_bottom

<?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="wrap_content"
    android:background="@android:color/white"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:drawableLeft="@drawable/ic_check_666666_24dp"
            android:drawablePadding="16dp"
            android:gravity="center_horizontal"
            android:padding="16dp"
            android:text="@string/dialog_ok"
            android:textColor="#666666"
            android:textSize="14sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <TextView
            android:id="@+id/tv_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:drawableLeft="@drawable/ic_close_666666_24dp"
            android:drawablePadding="16dp"
            android:gravity="center_horizontal"
            android:padding="16dp"
            android:text="@string/dialog_cancel"
            android:textColor="#666666"
            android:textSize="14sp" />
    </LinearLayout>
</LinearLayout>

style

<resources>
    <style name="BottomDialog" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

    <style name="BottomDialog.Animation" parent="Animation.AppCompat.Dialog">
        <item name="android:windowEnterAnimation">@anim/translate_dialog_in</item>
        <item name="android:windowExitAnimation">@anim/translate_dialog_out</item>
    </style>
</resources>

anim

translate_dialog_in

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
           android:duration="300"
           android:fromXDelta="0"
           android:fromYDelta="100%"
           android:toXDelta="0"
           android:toYDelta="0">
</translate>

translate_dialog_out

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
           android:duration="300"
           android:fromXDelta="0"
           android:fromYDelta="0"
           android:toXDelta="0"
           android:toYDelta="100%">
</translate>

代码如下

    @OnClick(R.id.log_out_layout)
    public void onLogOutClicked() {
        final Dialog mDialog = new Dialog(this.getActivity(), R.style.BottomDialog);
        View contentView = LayoutInflater.from(this.getActivity()).inflate(R.layout.dialog_bottom, null);
        mDialog.setContentView(contentView);

        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;
        contentView.setLayoutParams(layoutParams);

        mDialog.getWindow().setGravity(Gravity.BOTTOM);
        mDialog.setCanceledOnTouchOutside(true);
        mDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
        mDialog.show();

        TextView tvOk = (TextView) contentView.findViewById(R.id.tv_ok);
        tvOk.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                System.exit(0);//系统退出
            }
        });

        TextView tvCancel = (TextView) contentView.findViewById(R.id.tv_cancel);
        tvCancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mDialog.cancel();
            }
        });
    }
时间: 2024-08-29 22:13:09

Android编程入门--底部Dialog弹窗的相关文章

《Delphi XE6 android 编程入门教程》推荐

近5.6已经没有看见关于delphi的新技术的书出来了(看来在国内delphi的使用量确实很低了), 高勇同学最近出了一本<Delphi XE6 android 编程入门教程>,上周刚拿到,这一周大概看了一遍. 严格意义上,这本书不是按正常的出版的格式来的,大部分应该是类似博客的汇总.delphi 开发android 还是一个新事物,也就是去年才开始,相关资料也是少之甚少,这么短的的时间,能汇总出出这么高质量的资料, 先谢谢高勇同学能花这么多业余时间完成这么一项艰巨的任务. 首先,这本书主要介

[电子书] 《Android编程入门很简单》

<Android编程入门很简单>是一本与众不同的Android学习读物,是一本化繁为简,把抽象问题具体化,把复杂问题简单化的书.本书避免出现云山雾罩.晦涩难懂的讲解,代之以轻松活泼.由浅入深的剖析.这必将使得阅读本书的堵着少走弯路,快速上手,从而建立学习Android开发的信心. 链接: http://pan.baidu.com/s/1sj2xesH 密码: juab

Android编程:底部弹出的对话框

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN10 开发环境:Android Studio 2.2 Preview 3 说明: 两种方法实现底部弹出的对话框: Dialog DialogFragment 推荐用DialogFragment 效果图: 布局文件dialog_select_call.xml: <?xml version="1.0" encoding="utf-8"?> &l

Android编程入门--BottomNavigationView+ViewPager

参考博客:Android (争取做到)最全的底部导航栏实现方法 Bottom Navigation是5.0(API level 21)新出的一种符合MD规范的导航栏规范. 规范参考:Android Bottom navigation 规范一:使用方法 3个比较火的开源库,GitHub - aurelhubert/ahbottomnavigation,GitHub - roughike/BottomBar, Ashok-Varma/BottomNavigation ashokvarma 参考博客:

Android编程入门--android.support.v7.widget.Toolbar

参考博客:利用 v7 Toolbar 自定义 Android ActionBar 布局 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://sc

Android编程入门--简单闪屏界面

Manifest <activity android:name=".ui.activity.WelcomeActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android

Android编程入门--开源框架OKHttp

官网地址:http://square.github.io/okhttp/ github地址:square/okhttp 参考博客:Android okHttp网络请求之Get/Post请求 参考博客:Android okHttp网络请求之文件上传下载 session相关博客:利用okhttp框架实现包含验证码的用户登录,保持session操作 cookie相关博客:OkHttp3的基本用法 创建一个工具类 OkHttpManager 初始化方法 /** * OkHttpManager */ pu

Android编程入门--RecyclerView使用

布局 <android.support.v7.widget.RecyclerView android:id="@+id/rv_department" android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" android:clipToPadding="false&q

Android编程入门--开源框架EventBus

github地址:greenrobot / EventBus 参考博客:EventBus3.0详解 参考博客: Android事件总线(一)EventBus3.0用法全解析 参考博客:Android消息传递之EventBus 3.0使用详解 先准备订阅 EventBus.getDefault().register(this); @Subscribe public void onMainEvent(MessageEvent messageEvent) { if (messageEvent.getM