我有这个DialogFragment。当我显示它时,它变为全屏,我的意思是它与当前屏幕重叠。如何使它像AlertDialog一样小?
我猜这是因为RelativeLayout因此我将LinearLayout包装在RelativeLayout之外,但没有任何变化。
public class LoginDialogFragment extends DialogFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme);
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.login_dialog, container, false);
final EditText emailEditText = (EditText)v.findViewById(R.id.emailEditText);
final EditText passwordEditText = (EditText)v.findViewById(R.id.passwordEditText);
final Button loginButton = (Button)v.findViewById(R.id.loginButton);
loginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
checkLogin(emailEditText.getText().toString(), passwordEditText.getText().toString());
}
});
return v;
}
}
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/loginTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/loginDialogTitle"
android:textColor="@color/White"
android:textSize="20sp" />
<EditText
android:id="@+id/emailEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/loginTitleTextView"
android:layout_weight="1"
android:ems="10"
android:inputType="textEmailAddress" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/emailEditText"
android:layout_weight="1"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="@+id/passwordTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/passwordEditText"
android:layout_alignBottom="@+id/passwordEditText"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:text="@string/password"
android:textColor="@color/White"
android:textSize="16sp" />
<TextView
android:id="@+id/emailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/emailEditText"
android:layout_alignBottom="@+id/emailEditText"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:text="@string/email"
android:textColor="@color/White"
android:textSize="16sp" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/passwordEditText"
android:text="@string/loginButtonText" />
</RelativeLayout>
</LinearLayout>
答案 0 :(得分:2)
在setStyle(STYLE_NORMAL, android.R.style.Theme_Dialog);
中呼叫setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme);
而不是onCreate()
。它有帮助吗?