亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android編程自定義扁平化對(duì)話框示例

 更新時(shí)間:2017年06月29日 11:02:36   作者:a771948524  
這篇文章主要介紹了Android編程自定義扁平化對(duì)話框,結(jié)合具體實(shí)例形式分析了Android自定義扁平化對(duì)話框的布局與功能相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程自定義扁平化對(duì)話框。分享給大家供大家參考,具體如下:

平時(shí)我們開發(fā)的大多數(shù)的Android、iOS的APP,它們的風(fēng)格都是擬物化設(shè)計(jì)。如Android 4.X、iOS 7、WP8采用的是扁平化設(shè)計(jì),可以看出扁平化設(shè)計(jì)是未來UI設(shè)計(jì)的趨勢。其實(shí)扁平化設(shè)計(jì)要比擬物化設(shè)計(jì)要簡單一點(diǎn),扁平化設(shè)計(jì)更加的簡約,給人視覺上更加舒服。

Shamoo想到在Android平臺(tái)上弄一個(gè)扁平化的對(duì)話框。參考過一篇帖子,然后改了一下。

這個(gè)Demo比較簡單,首先是一個(gè)dialog的布局文件,這個(gè)dialog的布局要實(shí)例化成對(duì)話框可以通過AlertDialog.Builder的setView方法,將LayoutInflater實(shí)例化的dialog布局設(shè)置對(duì)話框具體顯示內(nèi)容。效果圖如下:

下面直接貼代碼

DialogWindows.Java

package com.example.dialogwindows;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
public class DialogWindows extends Activity {
  private Button button;
  private View dialogView;
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    button = (Button) findViewById(R.id.btn);
    button.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        Builder builder = myBuilder(DialogWindows.this);
        final AlertDialog dialog = builder.show();
        //點(diǎn)擊屏幕外側(cè),dialog不消失
        dialog.setCanceledOnTouchOutside(false);
        Button btnOK = (Button) dialogView.findViewById(R.id.btn_ok);
        btnOK.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            Toast.makeText(DialogWindows.this, "你點(diǎn)擊了確定按鈕", Toast.LENGTH_SHORT).show();
            dialog.dismiss();
          }
        });
        Button btnCancel = (Button) dialogView.findViewById(R.id.btn_cancel);
        btnCancel.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          Toast.makeText(DialogWindows.this, "你點(diǎn)擊了取消按鈕", Toast.LENGTH_SHORT).show();
          dialog.dismiss();
        }
      });
        ImageButton customviewtvimgCancel = (ImageButton) dialogView.findViewById(R.id.btn_exit);
        customviewtvimgCancel.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            Toast.makeText(DialogWindows.this, "你點(diǎn)擊了退出按鈕", Toast.LENGTH_SHORT).show();
            dialog.dismiss();
          }
        });
      }
    });
  }
  protected Builder myBuilder(Context context) {
    LayoutInflater inflater = getLayoutInflater();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    dialogView = inflater.inflate(R.layout.dialog, null);
    return builder.setView(dialogView);
  }
}

dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <!-- 標(biāo)題欄 -->
  <RelativeLayout
    android:id="@+id/dialog_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#1A94F9" >
    <TextView
      android:id="@+id/tv_title"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:padding="10dp"
      android:text="@string/about"
      android:textColor="#000000" />
    <ImageButton
      android:id="@+id/btn_exit"
      android:layout_width="40dp"
      android:layout_height="40dp"
      android:layout_alignParentRight="true"
      android:layout_centerVertical="true"
      android:background="@drawable/canceltor" />
  </RelativeLayout>
  <!-- 顯示的內(nèi)容 -->
  <LinearLayout
    android:id="@+id/dialog_msg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_below="@id/dialog_title"
    android:padding="20dp" >
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/author"
      android:textColor="#ffffff" />
    <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:linksClickable="true"
      android:text="@string/blog"
      android:textColor="#ffffff" />
  </LinearLayout>
  <!-- 底部按鈕 -->
  <LinearLayout
    android:id="@+id/customviewlayLink"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/dialog_msg"
    android:orientation="horizontal"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingBottom="20dp" >
    <Button
      android:id="@+id/btn_ok"
      android:layout_width="fill_parent"
      android:layout_height="40dp"
      android:background="@drawable/linkbtnbged"
      android:linksClickable="true"
      android:layout_weight="1"
      android:layout_marginRight="10dp"
      android:text="@string/btn_ok" />
    <Button
      android:id="@+id/btn_cancel"
      android:layout_width="fill_parent"
      android:layout_height="40dp"
      android:linksClickable="true"
      android:background="@drawable/linkbtnbged"
      android:text="@string/btn_cancel"
      android:layout_marginLeft="10dp"
      android:layout_weight="1" />
  </LinearLayout>
</RelativeLayout>

main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >
  <Button
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/show_dialog" />
</RelativeLayout>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android實(shí)現(xiàn)倒計(jì)時(shí)結(jié)束后跳轉(zhuǎn)頁面功能

    Android實(shí)現(xiàn)倒計(jì)時(shí)結(jié)束后跳轉(zhuǎn)頁面功能

    最近在工作中遇到一個(gè)需求,需要在倒計(jì)時(shí)一段時(shí)間后進(jìn)行跳轉(zhuǎn)頁面,通過查找相關(guān)資料發(fā)現(xiàn)其中涉及的知識(shí)還不少,所以分享出來,下面這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)倒計(jì)時(shí)結(jié)束后跳轉(zhuǎn)頁面功能的相關(guān)資料,需要的朋友可以參考下。
    2017-11-11
  • Android使用BroadcastReceiver監(jiān)聽網(wǎng)絡(luò)連接狀態(tài)的改變

    Android使用BroadcastReceiver監(jiān)聽網(wǎng)絡(luò)連接狀態(tài)的改變

    這篇文章主要為大家詳細(xì)介紹了Android使用BroadcastReceiver監(jiān)聽網(wǎng)絡(luò)連接狀態(tài)的改變,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android 代碼寫控件代替XML簡單實(shí)例

    Android 代碼寫控件代替XML簡單實(shí)例

    這篇文章主要介紹了Android 代碼寫控件代替XML簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • 修改Android中hosts文件的步驟詳解

    修改Android中hosts文件的步驟詳解

    有朋友問Android怎么修改Hosts?對(duì)于這個(gè)問題,由于手頭并沒有Android設(shè)備,所以只能從網(wǎng)上搜羅了方法并總結(jié)出來,下面這篇文章主要介紹了修改Android中hosts文件的步驟,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • 如何調(diào)用百度地圖API實(shí)現(xiàn)手機(jī)自動(dòng)定位

    如何調(diào)用百度地圖API實(shí)現(xiàn)手機(jī)自動(dòng)定位

    api手機(jī)自動(dòng)定位,通過聲明地址解析器,獲取當(dāng)前坐標(biāo),如何調(diào)用百度地圖api實(shí)現(xiàn)手機(jī)自動(dòng)定位呢?接下來,一起跟小編來學(xué)習(xí)吧。
    2015-09-09
  • Android實(shí)現(xiàn)ImageView陰影和圖層效果

    Android實(shí)現(xiàn)ImageView陰影和圖層效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)ImageView陰影和圖層效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • android Imageview 圖片覆蓋具體實(shí)現(xiàn)

    android Imageview 圖片覆蓋具體實(shí)現(xiàn)

    android Imageview 圖片覆蓋實(shí)現(xiàn)及注意事項(xiàng)如下,感興趣的朋友可以參考下哈
    2013-06-06
  • Android 調(diào)用百度地圖API示例

    Android 調(diào)用百度地圖API示例

    在Android開發(fā)中有一個(gè)非常重要的應(yīng)用就是實(shí)時(shí)定位,通過手機(jī)在手機(jī)地圖上進(jìn)行實(shí)時(shí)定位,定位當(dāng)前手機(jī)的位置,這篇文章主要介紹了Android 調(diào)用百度地圖API示例,有興趣的可以了解一下。
    2017-01-01
  • Jetpack?Compose實(shí)現(xiàn)點(diǎn)擊事件click的多種方法

    Jetpack?Compose實(shí)現(xiàn)點(diǎn)擊事件click的多種方法

    這篇文章主要介紹了Jetpack?Compose實(shí)現(xiàn)點(diǎn)擊事件的多種方法,Jetpack?Compose是一款基于Kotlin的聲明式UI工具包,可以方便地創(chuàng)建漂亮的用戶界面,下面我們就來看看Jetpack?Compose添加點(diǎn)擊事件都可以怎么實(shí)現(xiàn)
    2024-02-02
  • Kotlin使用TransitionDrawable實(shí)現(xiàn)顏色漸變效果流程講解

    Kotlin使用TransitionDrawable實(shí)現(xiàn)顏色漸變效果流程講解

    這篇文章主要介紹了Kotlin使用TransitionDrawable實(shí)現(xiàn)顏色漸變效果,這里,我們通過TransitionDrawable顯示顏色漸變效果,包括背景顏色的變化,以及圖片與圖片的漸變效果
    2023-02-02

最新評(píng)論