Android 從底部彈出Dialog(橫向滿屏)的實(shí)例代碼
項(xiàng)目中經(jīng)常需要底部彈出框,這里我整理一下其中我用的比較順手的一個(gè)方式(底部彈出一個(gè)橫向滿屏的dialog)。
效果圖如下所示(只顯示關(guān)鍵部分):
步驟如下所示:
1.定義一個(gè)dialog的布局(lay_share.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="@color/white" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:paddingBottom="@dimen/padding_15" android:paddingTop="@dimen/padding_15"> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="@dimen/padding_5" android:drawableTop="@mipmap/ic_weixin_share" android:gravity="center" android:text="微信" android:textColor="@color/color_999999" android:textSize="@dimen/text_14" /> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="@dimen/padding_5" android:drawableTop="@mipmap/ic_circle_share" android:gravity="center" android:text="朋友圈" android:textColor="@color/color_999999" android:textSize="@dimen/text_14" /> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="@dimen/padding_5" android:drawableTop="@mipmap/ic_weibo_share" android:gravity="center" android:text="微博" android:textColor="@color/color_999999" android:textSize="@dimen/text_14" /> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="0.5dp" android:layout_marginLeft="@dimen/padding_10" android:layout_marginRight="@dimen/padding_10" android:background="@color/color_c9c9c9" /> <TextView android:id="@+id/tv_cancel" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="@dimen/padding_15" android:text="取消" android:textColor="@color/color_666666" android:textSize="@dimen/text_18" /> </LinearLayout>
2.定義彈出框彈出動(dòng)畫(dialog_enter.xml)
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="300" android:fromYDelta="100%p" android:toYDelta="0" /> </set> dialog_enter.xml
3.定義彈出框隱藏動(dòng)畫(dialog_exit.xml)
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="300" android:fromYDelta="0" android:toYDelta="100%p" /> </set> dialog_exit.xml
4.定義動(dòng)畫style
<!--彈出框動(dòng)畫--> <style name="share_animation" parent="android:Animation"> <item name="android:windowEnterAnimation">@anim/dialog_enter</item> <item name="android:windowExitAnimation">@anim/dialog_exit</item> </style>
5.定義對(duì)話框樣式
<!-- 對(duì)話框樣式 --> <style name="dialog_bottom_full" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:scrollHorizontally">true</item> </style>
6.最后,在需要從底部彈出dialog的地方,直接調(diào)用showDialog()方法
/** * 顯示分享彈出框 */ private void showDialog() { if (mShareDialog == null) { initShareDialog(); } mShareDialog.show(); } /** * 初始化分享彈出框 */ private void initShareDialog() { mShareDialog = new Dialog(this, R.style.dialog_bottom_full); mShareDialog.setCanceledOnTouchOutside(true); mShareDialog.setCancelable(true); Window window = mShareDialog.getWindow(); window.setGravity(Gravity.BOTTOM); window.setWindowAnimations(R.style.share_animation); View view = View.inflate(this, R.layout.lay_share, null); view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mShareDialog != null && mShareDialog.isShowing()) { mShareDialog.dismiss(); } } }); window.setContentView(view); window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//設(shè)置橫向全屏 }
以上所述是小編給大家介紹的Android 從底部彈出Dialog(橫向滿屏)的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android 全局Dialog的簡(jiǎn)單實(shí)現(xiàn)方法
- Android使用Dialog風(fēng)格彈出框的Activity
- Android實(shí)現(xiàn)從底部彈出的Dialog示例(一)
- Android 中從屏幕左下角彈出Dialog動(dòng)畫效果的實(shí)現(xiàn)代碼
- Android中自定義的dialog中的EditText無(wú)法彈出輸入法解決方案
- Android 仿蘋果底部彈出Dialog
- Android解決dialog彈出時(shí)無(wú)法捕捉Activity的back事件的方法
- Android自定義彈出框dialog效果
- Android 解決dialog彈出時(shí)無(wú)法捕捉Activity的back事件問(wèn)題
- Android 8.0如何完美適配全局dialog懸浮窗彈出
相關(guān)文章
android Web跳轉(zhuǎn)到app指定頁(yè)面并傳遞參數(shù)實(shí)例
這篇文章主要介紹了android Web跳轉(zhuǎn)到app指定頁(yè)面并傳遞參數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-03-03Android菜單操作之創(chuàng)建并響應(yīng)菜單
這篇文章主要介紹了Android菜單操作之創(chuàng)建并響應(yīng)菜單的相關(guān)資料,如何使用代碼創(chuàng)建菜單項(xiàng),給菜單項(xiàng)分組,及各種響應(yīng)菜單事件的方法,需要的朋友可以參考下2016-04-04Android XmlPullParser 方式解析 Xml 文檔
這篇文章主要介紹了Android XmlPullParser 方式解析 Xml 文檔的相關(guān)資料,需要的朋友可以參考下2017-06-06Android實(shí)現(xiàn)快速滾動(dòng)FastScrollView效果
這篇文章主要介紹了Android實(shí)現(xiàn)快速滾動(dòng)FastScrollView效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08Android LayoutTransiton實(shí)現(xiàn)簡(jiǎn)單的錄制按鈕
這篇文章主要介紹了Android LayoutTransiton實(shí)現(xiàn)簡(jiǎn)單的錄制按鈕,主要實(shí)現(xiàn)開始,暫停,停止和顯示錄制時(shí)間長(zhǎng)度,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06Android實(shí)現(xiàn)View滑動(dòng)效果的6種方法
這篇文章主要介紹了Android實(shí)現(xiàn)View滑動(dòng)的6種方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-03-03