亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1540 | 回復(fù): 0
打印 上一主題 下一主題

[Android] Android簡單例子——IpHone樣式AlertDialog [復(fù)制鏈接]

論壇徽章:
1
操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-08-21 06:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-06-01 10:05 |只看該作者 |倒序?yàn)g覽
本帖最后由 lovefan 于 2015-06-01 10:06 編輯

此例子源于網(wǎng)絡(luò),下載下來之后,自己加了寫注釋,作為總結(jié),發(fā)到博客中,謝謝原作者

通過這個例子學(xué)到的東西

1.自定義對話框的使用

2.程序中使用顏色如何進(jìn)行存放,增加復(fù)用性

3.加深線性布局、常用控件的使用

1.實(shí)現(xiàn)效果


2.顏色值文件
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3.     <drawable name="white">#FFFFFF</drawable>
  4.     <color name="White">#FFFFFF</color>
  5.     <color name="Black">#000000</color>
  6.     <color name="grey">#D7D4D4</color>
  7.     <color name="red">#FF0000</color>

  8. </resources>
復(fù)制代碼
3.第一個界面布局文件
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="wrap_content"
  5.     android:layout_gravity="center_horizontal|center_vertical"
  6.     android:orientation="vertical">
  7.    
  8.     <LinearLayout
  9.         android:orientation="vertical"
  10.         android:background="@drawable/alert"
  11.         android:layout_width="match_parent"
  12.         android:layout_height="wrap_content"
  13.         android:gravity="center_horizontal"
  14.         android:layout_marginLeft="20dip"
  15.         android:layout_marginRight="20dip">
  16.         
  17.         <TextView android:id="@+id/dialog_title"
  18.              android:layout_width="wrap_content"
  19.              android:layout_height="wrap_content"
  20.              android:layout_marginTop="15dip"
  21.              android:textColor="#ffffff"
  22.              android:textStyle="bold"
  23.              android:textSize="17sp"
  24.              android:text="About to call 323"/>
  25.         
  26.         <TextView android:id="@+id/dialog_message"
  27.              android:layout_width="wrap_content"
  28.              android:layout_height="wrap_content"
  29.              android:layout_margin="10dip"
  30.              android:gravity="center_horizontal"
  31.              android:textSize="15sp"
  32.              android:textColor="#ffffff"
  33.              android:text="Are you sure you want to proceed?" />

  34.          <Button
  35.              android:id="@+id/ok"
  36.              android:layout_width="fill_parent"
  37.              android:layout_height="40dip"
  38.              android:layout_marginBottom="10dip"
  39.              android:layout_marginLeft="10dip"
  40.              android:layout_marginRight="10dip"
  41.              android:background="@drawable/custom_button"
  42.              android:textColor="@color/White"
  43.              android:textSize="17sp"
  44.              android:textStyle="bold"
  45.              android:text="OK"/>
  46.     </LinearLayout>
  47. </LinearLayout>
復(fù)制代碼
4.第二個界面的布局文件
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="wrap_content"
  5.     android:layout_gravity="center_horizontal|center_vertical"
  6.     android:orientation="vertical">
  7.    
  8.     <LinearLayout
  9.         android:orientation="vertical"
  10.         android:background="@drawable/alert"
  11.         android:layout_width="match_parent"
  12.         android:layout_height="wrap_content"
  13.         android:gravity="center_horizontal"
  14.         android:layout_marginLeft="20dip"
  15.         android:layout_marginRight="20dip">
  16.         
  17.         <TextView android:id="@+id/dialog_title_2"
  18.              android:layout_width="wrap_content"
  19.              android:layout_height="wrap_content"
  20.              android:layout_marginTop="15dip"
  21.              android:textColor="#ffffff"
  22.              android:textStyle="bold"
  23.              android:textSize="17sp"
  24.              android:text="About to call 323"/>
  25.         
  26.         <TextView android:id="@+id/dialog_message_2"
  27.              android:layout_width="wrap_content"
  28.              android:layout_height="wrap_content"
  29.              android:layout_margin="10dip"
  30.              android:gravity="center_horizontal"
  31.              android:textSize="15sp"
  32.              android:textColor="#ffffff"
  33.              android:text="Are you sure you want to proceed?" />
  34.         <LinearLayout
  35.             android:layout_width="fill_parent"
  36.             android:layout_height="wrap_content"
  37.             android:layout_marginBottom="10dip"
  38.             android:layout_marginTop="10dip"
  39.             android:gravity="center_horizontal"
  40.             android:orientation="horizontal" >

  41.             <Button
  42.                 android:id="@+id/cancel_2"
  43.                 android:layout_width="0dip"
  44.                 android:layout_height="40dip"
  45.                 android:layout_gravity="left"
  46.                 android:layout_marginLeft="10dip"
  47.                 android:layout_weight="1"
  48.                 android:background="@drawable/custom_button"
  49.                 android:text="取消"
  50.                 android:textColor="@color/White"
  51.                 android:textStyle="bold" />

  52.             <Button
  53.                 android:id="@+id/ok_2"
  54.                 android:layout_width="0dip"
  55.                 android:layout_height="40dip"
  56.                 android:layout_marginBottom="10dip"
  57.                 android:layout_marginRight="10dip"
  58.                 android:layout_weight="1"
  59.                 android:background="@drawable/custom_button"
  60.                 android:text="確定"
  61.                 android:textColor="@color/White"
  62.                 android:textStyle="bold" />
  63.         </LinearLayout>
  64.     </LinearLayout>
  65. </LinearLayout>
復(fù)制代碼
5.核心代碼文件
  1. public class MainActivity extends Activity {

  2.     private Button btn;
  3.     private Button btn2;
  4.     @Override
  5.     protected void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.         setContentView(R.layout.activity_main);
  8.         
  9.         btn = (Button) findViewById(R.id.btn1);
  10.         
  11.         /**增加監(jiān)聽事件**/
  12.         btn.setOnClickListener(new OnClickListener() {
  13.             
  14.             @Override
  15.             public void onClick(View view) {
  16.                 // TODO Auto-generated method stub
  17.                 showCustomMessageOK("提示信息","不能進(jìn)行此項(xiàng)操作");
  18.             }

  19.         });
  20.         
  21.         btn2 = (Button) findViewById(R.id.btn2);
  22.         btn2.setOnClickListener(new OnClickListener() {
  23.             @Override
  24.             public void onClick(View view) {
  25.                 // TODO Auto-generated method stub
  26.                 showCustomMessageOKAndCancle("溫馨提示","是否確認(rèn)退出");
  27.             }
  28.         });
  29.     }
  30.    
  31.     /**
  32.      * 實(shí)現(xiàn)一個帶有確定和取消按鈕的對話框
  33.      * @param title
  34.      * @param message
  35.      */
  36.     protected void showCustomMessageOKAndCancle(String title, String message) {
  37.         // TODO Auto-generated method stub
  38.         
  39.         /**
  40.          * 創(chuàng)建一個Dialog對象,Dialog有兩個構(gòu)造法方法
  41.          * 1.
  42.          *
  43.          *
  44.          **/
  45.         final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
  46.         
  47.         /**為Dialog加載布局文件**/
  48.         dialog.setContentView(R.layout.ok_cancle_dialog_view);
  49.         /**為設(shè)置相應(yīng)的屬性值**/
  50.         ((TextView)dialog.findViewById(R.id.dialog_title_2)).setText(title);
  51.         ((TextView)dialog.findViewById(R.id.dialog_message_2)).setText(message);
  52.         ((Button) dialog.findViewById(R.id.cancel_2)).setOnClickListener(new OnClickListener() {
  53.             
  54.             @Override
  55.             public void onClick(View view) {
  56.                 // TODO Auto-generated method stub
  57.                 dialog.dismiss();
  58.             }
  59.         });
  60.         
  61.         ((Button) dialog.findViewById(R.id.ok_2)).setOnClickListener(new OnClickListener() {
  62.                
  63.                 @Override
  64.                 public void onClick(View view) {
  65.                     // TODO Auto-generated method stub
  66.                     MainActivity.this.finish();
  67.                     System.exit(0);
  68.                 }
  69.         });
  70.         dialog.show();
  71.     }
  72.     /**
  73.      * 創(chuàng)建一個只有確定按鈕的對話框
  74.      * @param title
  75.      * @param message
  76.      */
  77.     private void showCustomMessageOK(String title, String message) {
  78.         // TODO Auto-generated method stub
  79.         final Dialog dialog = new Dialog(MainActivity.this, android.R.style.Theme_Translucent_NoTitleBar);
  80.         dialog.setContentView(R.layout.ok_dialog_view);
  81.         ((TextView) dialog.findViewById(R.id.dialog_title)).setText(title);
  82.         ((TextView) dialog.findViewById(R.id.dialog_message)).setText(message);
  83.         ((Button) dialog.findViewById(R.id.ok)).setText("OK");
  84.         ((Button) dialog.findViewById(R.id.ok)).setOnClickListener(new OnClickListener() {
  85.             
  86.             @Override
  87.             public void onClick(View view) {
  88.                 // TODO Auto-generated method stub
  89.                 dialog.dismiss();
  90.             }
  91.         });
  92.         
  93.         dialog.show();
  94.     }
  95. }
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP