我在游戏中使用 DialogFragments 来获取一些弹出信息。它在运行 android 4.2 的 LG Nexus 4 上运行良好,在运行 2.3 的 Desire S 上运行良好。
但是,它不能在 Sony Xperia U(运行 4)上正确运行。这是发生的事情:
它不会将对话框放在屏幕中间,这在所有其他设备上都会发生,但它也会在对话框下方的屏幕上呈现一个大的黑色部分。
这是我的代码:
public void ShowMessage(String title, String msg)
{
Bundle b = new Bundle();
b.putString("title", title);
b.putString("msg", msg);
DialogFragment dialog = new DialogFragment_MsgBox();
dialog.setArguments(b);
dialog.show(getSupportFragmentManager(), "msgbox");
}
和
public class DialogFragment_MsgBox extends android.support.v4.app.DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle b = getArguments();
final Dialog dialog = new Dialog(getActivity(), R.style.SetmsgDialog);
dialog.setContentView(R.layout.simpleokdialog);
if(b.containsKey("title"))
dialog.setTitle(b.getString("title"));
else
dialog.setTitle("Message");
return dialog;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.simpleokdialog, container, false);
Bundle b = getArguments();
String msg = "";
if(b.containsKey("msg"))
{
msg = b.getString("msg");
}
TextView text = (TextView)v.findViewById(R.id.bericht);
text.setText(msg);
Button iv = (Button)v.findViewById(R.id.simpleOK);
iv.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// When button is clicked, call up to owning activity.
getDialog().dismiss();
}
});
// TODO Auto-generated method stub
return v;
}
}
并且还需要我用于对话框片段的样式:
<style name="SetmsgDialog">
<item name="android:background">#aac6775c</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:windowNoTitle">false</item>
<item name="android:textSize">14sp</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowTitleStyle">@style/setwindowTitleStyle</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:gravity">left</item>
</style>
什么会导致这种情况?对此问题有任何解决方案/提示或建议吗?