在DialogFragment

时间:2015-08-10 15:13:03

标签: android android-dialogfragment

我正在尝试自定义我创建的DialogFragment的背景颜色。默认情况下,当我设置窗口标题文本时,我会在黑色背景上显示白色文本。如何将其更改为我自己的颜色?

在查看类似问题时,我发现有些人建议在styles.xml中创建自定义样式。我试过这个但到目前为止还没有成功。

以下是我的代码的相关部分:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.event_planner_fragment, container, false);
        mRecyclerView = (RecyclerView) view.findViewById(R.id.drawerList);
        mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), null));

        //getDialog().setTitle("Fubar");
        //getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);

        mLayoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(mLayoutManager);

        return view;
    }

styles.xml我尝试过:

<style name="MyDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowBackground">@color/md_orange_900</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowTitleStyle">@null</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:gravity">center</item>
    </style>

1 个答案:

答案 0 :(得分:1)

Have a look at this。它会逐步向您显示您想要做的事情: