我正在开发一个Android应用程序,我对自定义对话框有疑问。
我这样做是为了打开一个自定义对话框:
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();
}
这就是它的布局:
<?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>
但它全屏开启。
如何将其作为AlertDialog
打开,我该怎么做?
答案 0 :(得分:6)
您必须使用android.R.style.Theme.Dialog
android.R.style.Theme_DeviceDefault
内容
答案 1 :(得分:2)
使用R.style.Theme_AppCompat_Dialog
以获得正确的对话框。
答案 2 :(得分:1)
只需制作自定义样式并将其应用于对话框......
<style name="full_screen_dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>