Styling custom dialog fragment not working

风流意气都作罢 提交于 2019-12-03 03:44:34
TrackDave

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.

I believe you need to set the theme on the actual Dialog and not the Fragment

Use this constructor to create your AlertDialog:

AlertDialog.Builder(Context context, int theme)

ie

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), theme)

I think you need to add one more item in style of your dialog. android:textColorSecondary will show color of un selected checkbox.

in your style add it.

</style>
    <style name="AppTheme.DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColorPrimary">@color/PrimaryBackgroundColor</item>
    <item name="colorAccent">@color/ColorBackgroundAccent</item>
     <item name="android:textColorSecondary">#000000</item>
</style>

It will make un Checked checkbox or toggle button edge color black. you need to change #000000 to color your want to show.

headuck

See if this helps - Android appcompat-v7:21.0.0 change material checkbox colors

In short, try setting android:textColorSecondary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!