Android自定義Dialog的用法-創(chuàng)新互聯(lián)

這篇文章主要講解了Android自定義Dialog的用法,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比河西網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式河西網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋河西地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

Android開發(fā)過程中,常常會(huì)遇到一些需求場(chǎng)景——在界面上彈出一個(gè)彈框,對(duì)用戶進(jìn)行提醒并讓用戶進(jìn)行某些選擇性的操作,

如退出登錄時(shí)的彈窗,讓用戶選擇“退出”還是“取消”等操作。

Android系統(tǒng)提供了Dialog類,以及Dialog的子類,常見如AlertDialog來(lái)實(shí)現(xiàn)此類功能。

一般情況下,利用Android提供的Dialog及其子類能夠滿足多數(shù)此類需求,然而,其不足之處體現(xiàn)在:

1. 基于Android提供的Dialog及其子類樣式單一,風(fēng)格上與App本身風(fēng)格可能不太協(xié)調(diào);

2. Dialog彈窗在布局和功能上有所限制,有時(shí)不一定能滿足實(shí)際的業(yè)務(wù)需求。

本文將通過在Dialog基礎(chǔ)上構(gòu)建自定義的Dialog彈窗,以最常見的確認(rèn)彈框?yàn)槔?/p>

本樣式相對(duì)比較簡(jiǎn)單:上面有一個(gè)彈框標(biāo)題(提示語(yǔ)),下面左右分別是“確認(rèn)”和“取消”按鈕,當(dāng)用戶點(diǎn)擊“確認(rèn)”按鈕時(shí),彈框執(zhí)行

相應(yīng)的確認(rèn)邏輯,當(dāng)點(diǎn)擊“取消”按鈕時(shí),執(zhí)行相應(yīng)的取消邏輯。

首先,自定義彈框樣式:

<&#63;xml version="1.0" encoding="utf-8"&#63;>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/dialog_bg"
  android:orientation="vertical" >

  <TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingTop="14dp"
    android:textColor="@color/login_hint"
    android:textSize="@dimen/text_size_18" />

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="14dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="30dp" >

    <TextView
      android:id="@+id/confirm"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginRight="10dp"
      android:layout_weight="1"
      android:background="@drawable/btn_confirm_selector"
      android:gravity="center"
      android:textColor="@color/white"
      android:textSize="@dimen/text_size_16" />

    <TextView
      android:id="@+id/cancel"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="10dp"
      android:layout_weight="1"
      android:background="@drawable/btn_cancel_selector"
      android:gravity="center"
      android:textColor="@color/login_hint"
      android:textSize="@dimen/text_size_16" />
  </LinearLayout>

</LinearLayout>

本文名稱:Android自定義Dialog的用法-創(chuàng)新互聯(lián)
本文地址:http://www.muchs.cn/article38/pispp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、品牌網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站建設(shè)云服務(wù)器

廣告

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

成都做網(wǎng)站