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

首頁 > 系統 > Android > 正文

Android編程自定義扁平化對話框示例

2019-10-22 18:33:24
字體:
來源:轉載
供稿:網友

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

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

Shamoo想到在Android平臺上弄一個扁平化的對話框。參考過一篇帖子,然后改了一下。

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

Android,對話框

下面直接貼代碼

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();        //點擊屏幕外側,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, "你點擊了確定按鈕", 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, "你點擊了取消按鈕", 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, "你點擊了退出按鈕", 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" >  <!-- 標題欄 -->  <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>  <!-- 顯示的內容 -->  <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>

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


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新巴尔虎右旗| 永德县| 青海省| 买车| 秦皇岛市| 沈丘县| 蓬安县| 林芝县| 锡林郭勒盟| 高雄县| 邹城市| 棋牌| 大理市| 黎城县| 大同市| 阿克陶县| 达尔| 石河子市| 会泽县| 进贤县| 峨眉山市| 遂平县| 仪陇县| 绥江县| 阿合奇县| 集贤县| 玉山县| 佛冈县| 遵义市| 年辖:市辖区| 大新县| 长春市| 嘉禾县| 达孜县| 修水县| 石嘴山市| 十堰市| 虞城县| 富平县| 南部县| 广东省|