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) | 設置此對話框是否取消與BACK關聯(lián)
setCanceledOnTouchOutside | 當設置窗口的邊界之外觸及這個對話框是否被取消
完整代碼點我下載GitHub
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Android 調(diào)用系統(tǒng)照相機拍照和錄像
本文主要介紹Android 調(diào)用系統(tǒng)照相機拍照和錄像的資料,這里整理了詳細的代碼,有需要的小伙伴可以參考下2016-09-09
Android中Listview下拉刷新和上拉加載更多的多種實現(xiàn)方案
本文大概通過三種方案給大家介紹了Android中Listview下拉刷新和上拉加載更多知識,非常不錯,具有參考借鑒價值,需要的朋友參考下2016-12-12
Android中關于百度糯米app關閉網(wǎng)頁或窗口的方法(99%人不知)
這篇文章主要介紹了Android中關于百度糯米app中關閉網(wǎng)頁或窗口的方法,其實解決方法到很簡單,但是很多人都不知道如何解決的,在網(wǎng)上也很難找到答案的,下面小編給大家揭曉答案,需要的朋友可以參考下2016-08-08
如何設置Android studio 3.0顯示光標返回上一次瀏覽位置的箭頭圖標
這篇文章主要介紹了如何設置Android studio 3.0顯示光標返回上一次瀏覽位置的箭頭圖標 很多朋友反映剛升級了Android studio 3.0,發(fā)現(xiàn)光標返回上一次瀏覽位置的箭頭圖標沒有了,下文給大家介紹的非常詳細,需要的朋友可以參考下2017-11-11

