Android BottomSheetDialog實現(xiàn)底部對話框的示例
Android 6.0新控件 BottomSheetDialog | 底部對話框 介紹及使用詳情
extends AppCompatDialog
Base class for Dialogs styled as a bottom sheet
基于Dialog樣式的一個底部對話框
先看看效果
對于彈出的內(nèi)容完全由自己來掌控,想實現(xiàn)什么樣子就實現(xiàn)什么樣子,很靈活
使用方法
BottomSheetDialog來自design兼容包,使用需要添加依賴。android studio 添加依賴如下:
dependencies { compile ‘com.android.support:design:23.2.0+‘ }
1.XML中添加布局文件
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="2"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> <ImageView android:id="@+id/image_man" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:selectableItemBackground" android:gravity="center" android:padding="10dp" android:src="@drawable/man"/> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> <ImageView android:id="@+id/image_women" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:selectableItemBackground" android:gravity="center" android:padding="10dp" android:src="@drawable/women"/> </RelativeLayout> </LinearLayout>
2.在代碼中使用
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play_bottom_sheet_dialog); showContentView(); bindingView.bottomsheet.textviewTitle.setText("BottomSheetDialog"); bindingView.bottomsheet.toolbarBack.setOnClickListener(this); bindingView.btnBsd1.setOnClickListener(this); initView(); } private void initView() { View view = View.inflate(this, R.layout.bottom_dialog, null); ImageView man = (ImageView) view.findViewById(R.id.image_man); ImageView women = (ImageView) view.findViewById(R.id.image_women); man.setOnClickListener(this); women.setOnClickListener(this); bsd1 = new BottomSheetDialog(this); bsd1.setContentView(view); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.toolbar_back: finish(); break; case R.id.btn_bsd1: bsd1.show(); break; case R.id.image_man: ToastUtil.show("男"); bsd1.dismiss(); break; case R.id.image_women: ToastUtil.show("女"); bsd1.dismiss(); break; } }
OK,這就完成了如效果圖上的效果,可以自己嘗試一下,下面貼上一些可以自己定制需求常用的方法
setCancelable(boolean cancelable) | 設(shè)置此對話框是否取消與BACK關(guān)聯(lián)
setCanceledOnTouchOutside | 當(dāng)設(shè)置窗口的邊界之外觸及這個對話框是否被取消
完整代碼點我下載GitHub
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android GPS獲取當(dāng)前經(jīng)緯度坐標(biāo)
這篇文章主要為大家詳細(xì)介紹了Android GPS獲取當(dāng)前經(jīng)緯度坐標(biāo),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05Android通過Service實現(xiàn)簡單的音樂播放
這篇文章主要介紹了Android通過Service實現(xiàn)簡單的音樂播放,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05Flutter利用ORM框架管理數(shù)據(jù)庫詳解
使用?ORM?框架最大的好處是簡化了數(shù)據(jù)庫維護(hù)的代碼量,使得我們可以專注于業(yè)務(wù)代碼實現(xiàn)。本篇,我們看看如何使用ORM框架管理數(shù)據(jù)庫版本遷移,需要的可以參考一下2023-04-04Android_UI 仿QQ側(cè)滑菜單效果的實現(xiàn)
相信大家對QQ側(cè)滑菜單的效果已經(jīng)不陌生了吧,側(cè)滑進(jìn)入個人頭像一側(cè),進(jìn)行對頭像的更改,我的收藏,QQ錢包,我的文件等一系列的操作,下面小編給大家分享Android_UI 仿QQ側(cè)滑菜單效果的實現(xiàn),一起看看吧2017-04-04Android jni調(diào)試打印char陣列的實例詳解
這篇文章主要介紹了Android jni調(diào)試打印char陣列的實例詳解的相關(guān)資料,通過此文希望能幫助到大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-08-08