国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android BottomSheetDialog實現(xiàn)底部對話框的示例

2019-10-22 18:09:43
字體:
供稿:網(wǎng)友

Android 6.0新控件 BottomSheetDialog | 底部對話框 介紹及使用詳情

extends AppCompatDialog

Base class for Dialogs styled as a bottom sheet

基于Dialog樣式的一個底部對話框

先看看效果

Android,BottomSheetDialog,對話框Android,BottomSheetDialog,對話框

對于彈出的內(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è)置窗口的邊界之外觸及這個對話框是否被取消

官方API

完整代碼點我下載GitHub

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 奈曼旗| 麻江县| 中江县| 富锦市| 云南省| 高青县| 彰武县| 丹巴县| 全椒县| 什邡市| 张家港市| 襄垣县| 长岛县| 始兴县| 当涂县| 方城县| 清丰县| 会昌县| 依安县| 旌德县| 牙克石市| 鄂尔多斯市| 佛教| 罗甸县| 滦平县| 合山市| 灵石县| 白水县| 英吉沙县| 瑞昌市| 巴中市| 青河县| 太仆寺旗| 莲花县| 喀喇沁旗| 福建省| 确山县| 高邑县| 驻马店市| 盐津县| 郯城县|