最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ANDROID中自定義對(duì)話框AlertDialog使用示例

 更新時(shí)間:2016年12月03日 17:02:10   作者:潘侯爺  
這篇文章主要為大家詳細(xì)介紹了Android中自定義對(duì)話框AlertDialog使用示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在Android開(kāi)發(fā)中,我們經(jīng)常會(huì)需要在Android界面上彈出一些對(duì)話框,比如詢問(wèn)用戶或者讓用戶選擇。這些功能我們叫它Android Dialog對(duì)話框,AlertDialog實(shí)現(xiàn)方法為建造者模式。AlertDialog中定義的一些對(duì)話框往往無(wú)法滿足我們關(guān)于對(duì)話框的需求,這時(shí)我們就需要通過(guò)自定義對(duì)話框VIEW來(lái)實(shí)現(xiàn)需求,這里我自定義一個(gè)登陸的提示對(duì)話框,效果圖顯示如下:

Layout(alertdialog自定義登陸按鈕)界面代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent">
  <Button
    android:text="自定義登陸"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button5"
    android:onClick="login"/>
</LinearLayout>

Layout(login_layout登陸窗口)界面:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent">
  <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:hint="請(qǐng)輸入用戶名"
    android:id="@+id/et_username"/>
  <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:hint="請(qǐng)輸入密碼"
    android:id="@+id/et_password"/>
</LinearLayout>

java功能實(shí)現(xiàn)代碼:

public class AlertDialogDemo extends AppCompatActivity {
  private EditText et_username,et_password;
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alertdialog);
  }
  public void login(View v){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("登錄"); 
    //通過(guò)布局填充器獲login_layout
    View view = getLayoutInflater().inflate(R.layout.login_layout,null); 
    //獲取兩個(gè)文本編輯框(密碼這里不做登陸實(shí)現(xiàn),僅演示)
    final EditText et_username = (EditText) view.findViewById(R.id.et_username);
    final EditText et_password = (EditText) view.findViewById(R.id.et_password);
    builder.setView(view);//設(shè)置login_layout為對(duì)話提示框
    builder.setCancelable(false);//設(shè)置為不可取消
    //設(shè)置正面按鈕,并做事件處理
    builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
        String name = et_username.getText().toString().trim();
        String pass = et_password.getText().toString().trim();
        Toast.makeText(AlertDialogDemo.this,name + "正在登錄....",Toast.LENGTH_SHORT).show();
      }
    });
    //設(shè)置反面按鈕,并做事件處理
    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialogInterface, int i) {
        Toast.makeText(AlertDialogDemo.this,"取消登錄",Toast.LENGTH_SHORT).show();
      }
    });
    builder.show();//顯示Dialog對(duì)話框
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

休宁县| 蒙阴县| 贵港市| 招远市| 英德市| 招远市| 闸北区| 饶平县| 页游| 合江县| 天津市| 乾安县| 同德县| 勃利县| 博白县| 绵竹市| 镇坪县| 中卫市| 五常市| 盐城市| 沙雅县| 双柏县| 西藏| 西盟| 吕梁市| 鄂托克旗| 彭泽县| 南和县| 巴里| 贡嘎县| 盐津县| 百色市| 论坛| 贵定县| 获嘉县| 河东区| 雷州市| 衡水市| 化州市| 武威市| 鄄城县|