国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 吉木乃县| 鹤庆县| 宣威市| 云和县| 禄丰县| 分宜县| 忻城县| 平武县| 镇远县| 昭通市| 慈利县| 泾阳县| 河源市| 淅川县| 滨州市| 盱眙县| 深泽县| 昭觉县| 容城县| 海南省| 都江堰市| 杨浦区| 西和县| 莆田市| 深州市| 上蔡县| 大荔县| 墨玉县| 赞皇县| 鞍山市| 莒南县| 胶州市| 阳春市| 茌平县| 五常市| 托里县| 钦州市| 石城县| 大宁县| 钟祥市| 五寨县|