欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程使用android-support-design實現(xiàn)MD風格對話框功能示例

 更新時間:2017年01月20日 11:42:48   作者:books1958  
這篇文章主要介紹了Android編程使用android-support-design實現(xiàn)MD風格對話框功能,涉及Android對話框、視圖、布局相關操作技巧,需要的朋友可以參考下

本文實例講述了Android編程使用android-support-design實現(xiàn)MD風格對話框功能。分享給大家供大家參考,具體如下:

首先上效果圖:

 

測試設備為紅米Note,系統(tǒng)為Android 4.4.4

說明:

1.在新版的android.support.v7包中,Google提供了一個新的AlertDialog類,即android.support.v7.app.AlertDialog。使用該類中的Builder可以直接創(chuàng)建Material Design風格的對話框,而不需要再借助于第三方庫。(即第一張圖的效果)

2.遺憾的是,上述第二張圖中轉圈樣式的ProgressBar暫無法使用系統(tǒng)組件。本例中使用的第三方庫來自:

compile 'com.github.rahatarmanahmed:circularprogressview:2.4.0'

3.代碼不多,并已簡單封裝為工具類:

package com.sinatj.demo.utils;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.sinatj.demo.R;
/**
 * UiUtil.
 * Created by admin on 15-12-22.
 */
public class UiUtil {
  private static AlertDialog showDialog(Context context, String title, String message, View contentView,
     String positiveBtnText, String negativeBtnText,
     DialogInterface.OnClickListener positiveCallback,
     DialogInterface.OnClickListener negativeCallback,
     boolean cancelable) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AppCompatAlertDialogStyle);
    builder.setTitle(title == null ? "提示" : title);
    if (message != null) {
      builder.setMessage(message);
    }
    if (contentView != null) {
      builder.setView(contentView);
    }
    if (positiveBtnText != null) {
      builder.setPositiveButton(positiveBtnText, positiveCallback);
    }
    if (negativeBtnText != null) {
      builder.setNegativeButton(negativeBtnText, negativeCallback);
    }
    builder.setCancelable(cancelable);
    return builder.show();
  }
  //普通對話框
  public static AlertDialog showSimpleDialog(Context context, String title, String message,
        String positiveBtnText, String negativeBtnText,
        DialogInterface.OnClickListener positiveCallback,
        DialogInterface.OnClickListener negativeCallback,
        boolean cancelable) {
    return showDialog(context, title, message, null, positiveBtnText, negativeBtnText, positiveCallback, negativeCallback, cancelable);
  }
  //帶ProgressBar的對話框
  public static AlertDialog showProgressDialog(Context context, String title, String message,
     String positiveBtnText, String negativeBtnText,
     DialogInterface.OnClickListener positiveCallback,
     DialogInterface.OnClickListener negativeCallback,
     boolean cancelable) {
    View view = LayoutInflater.from(context).inflate(R.layout.circular_progressbar, null);
    if (message != null) {
      final TextView messageTv = (TextView) view.findViewById(R.id.progressbar_msg);
      messageTv.setText(message);
    }
    return showDialog(context, title, null, view, positiveBtnText, negativeBtnText, positiveCallback, negativeCallback, cancelable);
  }
}

4.circular_progressbar布局文件,由一個第三方庫提供的ProgressBar和一個TextView組成:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:padding="20dp">
  <com.github.rahatarmanahmed.cpv.CircularProgressView
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:orientation="vertical"
    app:cpv_animAutostart="true"
    app:cpv_indeterminate="true" />
  <TextView
    android:id="@+id/progressbar_msg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_gravity="center_vertical"
    android:textSize="16sp"
    android:textColor="#111111"
    android:text="@string/main_waiting"/>
</LinearLayout>

5.AppCompatAlertDialogStyle為對話框的樣式,可指定文字顏色、按鈕顏色、背景色等。(本例中使用的時默認值)

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <!--對話框按鈕文字顏色-->
    <item name="colorAccent">#FFCC00</item>
    <!--對話框內容文字顏色-->
    <item name="android:textColorPrimary">#FFFFFF</item>
    <!--對話框背景色-->
    <item name="android:background">#5fa3d0</item>
</style>

更多關于Android相關內容感興趣的讀者可查看本站專題:《Android編程之activity操作技巧總結》、《Android資源操作技巧匯總》、《Android視圖View技巧總結》、《Android布局layout技巧總結》、《Android開發(fā)入門與進階教程》、《Android視圖View技巧總結》及《Android控件用法總結

希望本文所述對大家Android程序設計有所幫助。

相關文章

  • android使用surfaceview+MediaPlayer播放視頻

    android使用surfaceview+MediaPlayer播放視頻

    這篇文章主要為大家詳細介紹了android使用surfaceview+MediaPlayer播放視頻,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android自定義圓形倒計時進度條

    Android自定義圓形倒計時進度條

    這篇文章主要為大家詳細介紹了Android自定義圓形倒計時進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • android apk反編譯到java源碼的實現(xiàn)方法

    android apk反編譯到java源碼的實現(xiàn)方法

    Android由于其代碼是放在dalvik虛擬機上的托管代碼,所以能夠很容易的將其反編譯為我們可以識別的代碼,本文將詳細介紹,需要的朋友可以參考下
    2012-12-12
  • Android Messenger實現(xiàn)進程間通信及其原理

    Android Messenger實現(xiàn)進程間通信及其原理

    這篇文章主要為大家詳細介紹了Android Messenger實現(xiàn)進程間通信及其原理,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android實現(xiàn)拍照添加時間水印

    Android實現(xiàn)拍照添加時間水印

    這篇文章主要為大家詳細介紹了Android實現(xiàn)拍照添加時間水印,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android 基于google Zxing實現(xiàn)二維碼、條形碼掃描,仿微信二維碼掃描效果(推薦)

    Android 基于google Zxing實現(xiàn)二維碼、條形碼掃描,仿微信二維碼掃描效果(推薦)

    這篇文章主要介紹了 Android 基于google Zxing實現(xiàn)二維碼、條形碼掃描,仿微信二維碼掃描效果,非常不錯,具有參考借鑒價值,需要的朋友參考下
    2017-01-01
  • Android保存聯(lián)系人到通訊錄的方法

    Android保存聯(lián)系人到通訊錄的方法

    怎么保存聯(lián)系人數(shù)據(jù)到本機通訊錄?這篇文章主要為大家詳細介紹了Android保存聯(lián)系人到通訊錄的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Kotlin?RecyclerView滾動控件詳解

    Kotlin?RecyclerView滾動控件詳解

    RecyclerView是Android一個更強大的控件,其不僅可以實現(xiàn)和ListView同樣的效果,還有優(yōu)化了ListView中的各種不足。其可以實現(xiàn)數(shù)據(jù)縱向滾動,也可以實現(xiàn)橫向滾動(ListView做不到橫向滾動)。接下來講解RecyclerView的用法
    2022-12-12
  • 詳解Android應用中DialogFragment的基本用法

    詳解Android應用中DialogFragment的基本用法

    Android App中建議使用DialogFragment作為對話框的容器,DialogFragment類提供了創(chuàng)建對話框并管理其外觀需要的所有控件,本文主要內容便為詳解Android應用中DialogFragment的基本用法,而不再需要調用Dialog的方法需要的朋友可以參考下
    2016-05-05
  • Android LuBan與Compressor圖片壓縮方式

    Android LuBan與Compressor圖片壓縮方式

    本篇文章主要介紹了Android LuBan與Compressor圖片壓縮方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04

最新評論