標籤:.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 - 登入對話方塊