欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Android使用CardView實現(xiàn)圓角對話框

前言:隨著用戶體驗的不斷的加深,良好的UI視覺效果也必不可少,以前方方正正的對話框樣式在APP已不復存在,取而代之的是帶有圓角效果的Dialog,之前設置對畫框的圓角效果都是通過drawable/shape屬性來完成,隨著Google API的不斷更新,API 21(Android 5.0)添加了新的控件CardView,這使得圓角的實現(xiàn)更加方便快捷。

創(chuàng)新互聯(lián)建站是專業(yè)的定南網(wǎng)站建設公司,定南接單;提供成都網(wǎng)站設計、網(wǎng)站建設,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行定南網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

效果圖:

Android使用CardView實現(xiàn)圓角對話框

導入CardView依賴(API 21新控件)

implementation 'com.android.support:cardview-v7:26.1.0'

1.布局引用

<android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  app:cardCornerRadius="@dimen/dp_10">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
      android:id="@+id/tv_title"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/colorTabClick"
      android:gravity="center"
      android:padding="@dimen/dp_10"
      android:text="溫馨提示:確定修改維護詳情信息?"
      android:textColor="@color/bg_mainWhite"
      android:textSize="@dimen/dp_16" />

    <View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:background="@color/bg_line" />

    <TextView
      android:id="@+id/tv_des"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="@dimen/dp_10"
      android:gravity="top"
      />

    <View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:background="@color/bg_line" />

    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="50dp"
      android:orientation="horizontal">

      <TextView
        android:id="@+id/tv_cancel"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:gravity="center"
        android:text="取消"
        android:textSize="@dimen/dp_16" />

      <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="@color/bg_line" />

      <TextView
        android:id="@+id/tv_confirm"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:gravity="center"
        android:text="確定"
        android:textSize="@dimen/dp_16" />
    </LinearLayout>
  </LinearLayout>

</android.support.v7.widget.CardView>

1.cardCornerRadius屬性:設置圓角的弧度大小,這里設置的為10dp

2.CardView還有padding、cardUseCompatPadding(內(nèi)邊距)、background等屬性

3.CardView繼承自FrameLayout,使用時可以重新嵌套布局

2.代碼實現(xiàn)

/**
 * 展示對話框
 */
private void showDialog(String title) {
  //初始化布局文件
  View dialogView = View.inflate(mContext, R.layout.dialog_layout_test, null);
  //標題
  TextView tvTitle = (TextView) dialogView.findViewById(R.id.tv_title);
  //確定按鈕
  TextView tvConfirm = (TextView) dialogView.findViewById(R.id.tv_confirm);
  //取消按鈕
  TextView tvCancel = (TextView) dialogView.findViewById(R.id.tv_cancel);
  //描述信息
  TextView tvDes= (TextView) dialogView.findViewById(R.id.tv_des);
  //設置標題及描述信息
  tvTitle.setText(title);
  tvDes.setText("退出當前登錄后將要重新登錄!");
  //確定和取消按鈕監(jiān)聽事件
  tvConfirm.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      Intent intent = new Intent(mContext,LoginActivity.class);
      startActivity(intent);
      UIUtil.toast("退出成功,請重新登錄");
      getActivity().finish();
      mDialog.dismiss();
    }
  });
  tvCancel.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      mDialog.dismiss();
    }
  });
  mMessageBuilder = new AlertDialog.Builder(mContext);
  mDialog = mMessageBuilder.create();
  //設置背景色為透明,解決設置圓角后有白色直角的問題
  Window window=mDialog.getWindow();
  window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  mDialog.setView(dialogView);
  mDialog.setCanceledOnTouchOutside(false);//點擊屏幕不消失
  mDialog.show();
  //設置參數(shù)必須在show之后,不然沒有效果
  WindowManager.LayoutParams params = mDialog.getWindow().getAttributes();
  mDialog.getWindow().setAttributes(params);
}

使用的是V7包的AlertDialog實現(xiàn)的,當然也可以使用Dialog實現(xiàn)。

總結(jié):CardView實現(xiàn)對話框的圓角效果更加的方便,不用編寫shape屬性,當標題欄需要背景色時,也無需考慮設置標題欄的shape(不使用CardView時,如果不使用shape設置背景色,會導致左上和右上不會變成圓角)。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當前文章:Android使用CardView實現(xiàn)圓角對話框
標題路徑:http://www.aaarwkj.com/article4/gjopoe.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、移動網(wǎng)站建設、小程序開發(fā)網(wǎng)站維護、微信公眾號外貿(mào)網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設
青青草免费视频观看在线| 91嫩草中文字幕在线| 99久久久精品国产免费| 中文字幕有码手机在线看| 亚洲成人乱码一区二区| 蜜臀一区二区三区精品免费| 91久久国产香蕉熟女| 午夜少妇诱惑一区二区三区| 天堂社区人妻在线亚洲| 亚洲国产第一av导航| 亚洲综合色视频在线播放| 久久婷婷精品国产亚洲av| av免费观看一区二区三区| 未满十八禁止在线观看av| 亚洲中文字幕女同系列av专区| 日本一区欧美二区精品| 亚洲精品国产亚洲精品| 99人妻精品一区二区| 丰满少妇一区二区三区在线观看| 欧美人妻精品一区二区| 国产精品无遮挡猛进猛出| 人妻久久一区二区三区精品99| 成年人在线观看免费观看| 成年人免费在线不卡视频| 亚洲国产成人精品av在线| 日本一级a级黄免视频| 亚洲成年人黄片在线播放| 亚洲国产天堂久久综合| 国产农村妇女一区二区三区| 日韩午夜电影一区二区三区| 美女高潮呻吟免费观看久久久| 国产男女免费视频观看| 欧美黄片免费在线视频| 丰满人妻侵犯中文字幕| 精品人妻少妇av一区二区| 不卡的国产在线视频| 好狼色欧美激情国产区| 国产不卡视频观看网站| 97视频观看免费观看| 国产欧美日韩另类视频| 打开网址国语一级黄色片|