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

首頁 > 系統 > Android > 正文

Android BottomSheetDialog實現底部對話框的示例

2019-12-12 00:47:46
字體:
來源:轉載
供稿:網友

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

extends AppCompatDialog

Base class for Dialogs styled as a bottom sheet

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

先看看效果

對于彈出的內容完全由自己來掌控,想實現什么樣子就實現什么樣子,很靈活

使用方法

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關聯

setCanceledOnTouchOutside | 當設置窗口的邊界之外觸及這個對話框是否被取消

官方API

完整代碼點我下載GitHub

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉屏| 和林格尔县| 武川县| 濉溪县| 巴塘县| 廉江市| 青海省| 二手房| 玛曲县| 凤翔县| 南和县| 卓资县| 阿克| 内江市| 芮城县| 工布江达县| 葫芦岛市| 夏河县| 和政县| 叶城县| 兴隆县| 内丘县| 墨江| 南康市| 鸡东县| 乐业县| 丹阳市| 城步| 荔波县| 荣昌县| 新平| 静宁县| 广南县| 昭觉县| 太白县| 日喀则市| 吴江市| 朔州市| 桐庐县| 漳浦县| 胶南市|