gpt4 book ai didi

android - Android 中的全屏 DialogFragment(通过 ActionBar)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:05:18 24 4
gpt4 key购买 nike

我在全屏显示 DialogFragment 时遇到了一些问题。在我的应用程序中,我有一个 fragment ,当您单击某个按钮时,它会调用 DialogFragment。但是 DialogFragment 只是填充 fragment 的区域(在操作栏下方)。我希望它像这样填满整个屏幕:http://img845.imageshack.us/img845/8682/myimage2.png

有什么帮助吗?

     public class ItensActivity extends Fragment {
...
public void openDialogItens()
{
dialog = new ItemDialog();
dialog.show(getFragmentManager(), "");
getFragmentManager().executePendingTransactions();

}

public static class ItemDialog extends DialogFragment
{


@SuppressWarnings("deprecation")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(getContentView());
Dialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.FILL_PARENT;
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setAttributes(lp);
return dialog;
}

private View getContentView() {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.popup_item, null);
return view;
}
}

最佳答案

因此,经过大量搜索后,我还是找不到使用 API 5 使 DialogFragment 覆盖操作栏的方法。但是我找到了另一种方法来做到这一点,使 Fragment 在屏幕上调用一个新的 Activity ,主题为一个对话框。这个解决方案对我帮助很大,所以,我在这里分享它: https://stackoverflow.com/a/12275009/2327056

@StrikeForceZero using the idea from a google group post I was able to pull it off styling an activity. you would want to modify the height and width to a "dynamic" size of your choice preferably. Then set whatever ActionBar buttons you would like

<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>

--

public static void showAsPopup(Activity activity) {
//To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
LayoutParams params = activity.getWindow().getAttributes();
params.height = 850; //fixed height
params.width = 850; //fixed width
params.alpha = 1.0f;
params.dimAmount = 0.5f;
activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
setContentView(R.layout.activity_main);
}

关于android - Android 中的全屏 DialogFragment(通过 ActionBar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16253770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com