在android編程中,我想打開一個標題爲「Login」的彈出框。 內容應該是這樣的:如何打開對話框並使用佈局顯示它?
Login
Username
[________] (input field)
Password
[________] (password field)
[Cancel] [Login]
但我要表明,該使用佈局文件。我不想以編程方式添加所有這些。
任何人都可以告訴我一個如何做到這一點的例子嗎?
謝謝
在android編程中,我想打開一個標題爲「Login」的彈出框。 內容應該是這樣的:如何打開對話框並使用佈局顯示它?
Login
Username
[________] (input field)
Password
[________] (password field)
[Cancel] [Login]
但我要表明,該使用佈局文件。我不想以編程方式添加所有這些。
任何人都可以告訴我一個如何做到這一點的例子嗎?
謝謝
您應該使用彈出窗口類實現相同。 這裏有彈出窗口教程的一些鏈接:
這裏有你需要的步驟如下:
- = - 創建一個xml佈局文件(比如「my_popup_window.xml」)。使用您所提供的信息,這可以是: -
<LinearLayout(Vertical)>
<TextView("Login") />
<TextView("Username") />
<EditText />
<TextView("Password") />
<EditText />
<LinearLayout>
<Button("Cancel") />
<Button("Login") />
</LinearLayout>
</LinearLayout>
- = - 在你的活動中,創建一個方法 「showPopupWindow()」:
void showPopupWindow() {
// inflate your layout
View myPopupView = getLayoutInflater().inflate(R.layout.my_popup_window, null);
// Create the popup window; decide on the layout parameters
PopupWindow myPopupWindow = new PopupWindow(myPopupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// find and initialize your TextView(s), EditText(s) and Button(s); setup their behavior
// display your popup window
myPopupWindow.showAtLocation(myPopupView, Gravity.CENTER, 0, 0);
}
電話時,需要出示此此方法彈出窗口。
使用彈出窗口來實現它。 –