Styling custom dialog fragment not working

后端 未结 4 616
忘了有多久
忘了有多久 2021-02-06 14:13

I\'m trying to style all my dialog fragments to look the same in my app. The dialogs coming from my settings fragment are styled exactly the way I want it. For my custom dialo

4条回答
  •  一个人的身影
    2021-02-06 14:55

    Finally got an answer!!!

    It's an issue or bug with AppCompat 22+. Check out link here

    Apparently this was a bug with fragments and widgets weren't getting the material themed in a fragment. It seems they fixed this issue, but the issue still holds in a dialog fragment based on what I'm going through. The problem comes when you use the inflater instance passed to Fragment#onCreateView(). The workaround for now is to instead used the LayoutInflater from getActivity().getLayoutInflater() according to google.

    So I changed my code to:

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog, null);
    

    from:

    View view = LayoutInflater.from(getActivity().getApplicationContext()).inflate(R.layout.dialoge, null);
    

    All my widgets are now themed. Thanks everyone. Hopes this helps someone else.

提交回复
热议问题