Android AlertDialog - 登入對話方塊

來源:互聯網
上載者:User

標籤:.sh   out   登入   activity   tom   style   text   vertica   定義   

Step 1:

首先設定登入介面 - dialog_login.xml:使用者名稱和密碼輸入框,以及清除按鈕和登入按鈕

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:orientation="vertical"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:padding="8dp">        <TableLayout        android:id="@+id/dl_table"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:stretchColumns="1"        android:visibility="visible"        tools:layout_editor_absoluteX="8dp"        tools:layout_editor_absoluteY="8dp">        <TableRow>            <TextView                android:layout_width="60dp"                android:layout_height="wrap_content"                android:gravity="center"                android:text="使用者" />            <EditText                android:id="@+id/et_user"                android:layout_width="match_parent"                android:layout_height="wrap_content" />        </TableRow>        <TableRow            android:layout_width="match_parent"            android:layout_height="match_parent">            <TextView                android:layout_width="60dp"                android:layout_height="wrap_content"                android:gravity="center"                android:text="密碼" />            <EditText                android:id="@+id/et_password"                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:inputType="textPassword" />        </TableRow>    </TableLayout>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <Button            android:id="@+id/btn_clear"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="清除" />        <Button            android:id="@+id/btn_login"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:text="登入" />    </LinearLayout>

 

Step 2:

1. 將dialog_login.xml介面載入產生 View 對象;

2. 產生 dialog 對象,將自訂視圖載入進去;

3. 顯示該登入對話方塊;

public class CustomActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_custom);        View view = View.inflate(this, R.layout.dialog_login, null);        AlertDialog.Builder builder = new AlertDialog.Builder(this).setView(view);        builder.show();            }}

Note:調用 builder.show 等同於先建立 AlertDialog,再進行顯示

 

 

這樣就完成了登入對話方塊的建立,如果想要進一步擷取使用者輸入的資訊,點擊按鈕可以進行操作,增加如下代碼:

 

Android AlertDialog - 登入對話方塊

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.