小编Tra*_*ave的帖子

样式自定义对话框片段不起作用

我正在尝试将我的所有对话框片段设置为在我的应用中看起来相同.来自我的设置片段的对话框完全按照我想要的方式设置样式.对于我的自定义对话框片段,样式类似但不完全相同.出于某种原因,我的自定义对话框片段中的微调器,timepicker,datepicker,radiobuttons和edittext小部件不会选择相同的样式.事实上,小部件融入了白色背景,你无法看到它们在那里.我究竟做错了什么?

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>

<style name="Theme.Base" parent="AppTheme">
    <item name="colorPrimary">@color/PrimaryBackgroundColor</item>
    <item name="colorPrimaryDark">@color/SecondaryBackgroundColor</item>
    <item name="colorAccent">@color/ColorBackgroundAccent</item>
    <item name="android:textColorPrimary">@color/PrimaryTextColor</item>
    <item name="android:alertDialogTheme">@style/AppTheme.DialogStyle</item>
</style>
    <style name="AppTheme.DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColorPrimary">@color/PrimaryBackgroundColor</item>
    <item name="colorAccent">@color/ColorBackgroundAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我正在将主题应用于我的自定义对话框片段,如下所示:

 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_DialogStyle);
Run Code Online (Sandbox Code Playgroud)

我的设置对话框看起来像这样(我正是我想要的):

设置对话框片段

我的自定义对话框片段如下所示:

自定义对话框片段

如您所见,单选按钮选择了红色,您无法看到未选中的单选按钮.

android styling dialogfragment

5
推荐指数
1
解决办法
2893
查看次数

标签 统计

android ×1

dialogfragment ×1

styling ×1