本文介绍了自定义对话框打开全屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发一个Android应用程序,我有一个关于自定义对话框的问题。
I'm developing an Android application and I have a question about custom dialogs.
我这样做是为了打开自定义对话框:
I do this to open a custom dialog:
protected void showSetFriendEmailDialog()
{
// Create the dialog.
final Dialog emailDialog =
new Dialog(FriendHomeActivity.this, android.R.style.Theme_DeviceDefault);
emailDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
emailDialog.setCancelable(true);
emailDialog.setContentView(R.layout.dialog_add_friend_email);
// Get dialog widgets references.
final EditText editFriendsEmail = (EditText)emailDialog.findViewById(R.id.editEmailAddFriendEmail);
Button btnAccept = (Button)emailDialog.findViewById(R.id.btnAddFriendEmail);
// Set on click lister for accept button
btnAccept.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
// Get selected values
String friendEmail =
editFriendsEmail.getText().toString();
// Close dialog.
emailDialog.dismiss();
// TODO: Call api to send email to web service using friendsEmail var.
Log.v(TAG, "Friend email: " + friendEmail);
}
});
//now that the dialog is set up, it's time to show it
emailDialog.show();
}
这是它的布局:
And this is its layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textAddFriendEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/layout_set_friend_email"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/editEmailAddFriendEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<Button
android:id="@+id/btnAddFriendEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ok" />
</LinearLayout>
但它打开全屏。
But it opens full screen.
什么我必须做的,打开它作为一个 AlertDialog
?
What do I have to do to open it as an AlertDialog
?
推荐答案
您必须使用<$ C $的C android.R.style.Theme.Dialog
instenad > android.R.style.Theme_DeviceDefault
you have to use android.R.style.Theme.Dialog
instenad of android.R.style.Theme_DeviceDefault
这篇关于自定义对话框打开全屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!