【问题标题】:Changing dialogfragment background color (Using the Android Holo Colors Generator Xml Template)更改 dialogfragment 背景颜色(使用 Android Holo Colors Generator Xml 模板)
【发布时间】:2014-04-16 19:14:08
【问题描述】:

我所有的主题都在我的对话片段背景旁边工作。 我试图让我的 dialogFragment 背景变黑,但我做错了。

到目前为止,我在主题 xml 中得到了什么(请注意,我将它的顶部和底部进行了中继):

<style name="easydealtheme" parent="@style/_easydealtheme"/>

  <style name="_easydealtheme" parent="android:Theme.Holo.Light.DarkActionBar">

<item name="android:editTextBackground">@drawable/easydealtheme_edit_text_holo_light</item>

<item name="android:dropDownListViewStyle">@style/Listviewdropdowneasydealtheme</item>
<item name="android:textViewStyle">@style/Textvieweasydealtheme</item>
<item name="android:editTextStyle">@style/Edittexteasydealtheme</item>

<item name="android:alertDialogTheme">@style/Dialogeasydealtheme</item>
...

这是我在对话框的样式 xml 中得到的内容:

<style name="Dialogeasydealtheme" parent="android:Theme.Holo.Dialog">
<item name="android:textColor">#FFFFFF</item>
<item name="android:windowBackground">@color/test</item>
</style>

这是显示 dialogFragment 的代码:

 public static void ShowPhotoDialog(String title,File photoFile, FragmentManager fragM)
    {

        FragmentPhotoDialog photoD = new FragmentPhotoDialog();
        FragmentTransaction fTX  = fragM.BeginTransaction();
        photoD.SetStyle(DialogFragmentStyle.NoFrame, EasyDeal_Android.Resource.Style.easydealtheme);
        photoD.SetTile(title);
        photoD.SetPhotoFile(photoFile);
        photoD.Show(fTX, "Dialog");

    }

这里的结果不起作用(白色应该是黑色):

【问题讨论】:

  • 对话框文本颜色是否有效?
  • 自定义主题的父基主题是什么
  • 自定义主题父是:parent="android:Theme.Holo.Light.DarkActionBar"

标签: android android-layout android-fragments android-theme


【解决方案1】:

我疯狂地寻找这个问题的解决方案,直到找到解决方案。

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Setup the layout
        LayoutInflater inflater = getActivity().getLayoutInflater();
        final View root = inflater.inflate(*"YOUR LAYOUT"*, null);
        root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        //Customizing the dialog features
        final Dialog dialog = new Dialog(getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(root);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(getResources().getColor(*"YOUR SELECTED COLOR"*)));
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        return dialog;
    }

【讨论】:

    【解决方案2】:

    尝试将警报对话框背景更改为

    <style name="Dialogeasydealtheme" parent="android:Theme.Holo.Dialog">
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:background">@color/black</item>
    </style>
    

    如果发现任何问题,请告诉我。

    【讨论】:

    • 我确实将其更改为 dialogTheme 没有成功,bg 保持白色。
    • 好的,继续alertDialogTheme,但改变背景,如android:background
    • 好吧,我将 SetStyle 设置为 NoFrame,我将其删除,现在我可以看到颜色,但我真的希望将 noframe 背景颜色设置为黑色...我尝试了您的 alertDialog 版本,但没有工作
    • 我添加了一些代码也许会有所帮助。就像我说的,我已经将样式设置为无框架
    【解决方案3】:

    我找到了一个不是我最喜欢的解决方案,但它会做。

    我在布局中添加了背景。这是我的主要线性布局上的代码:

    <LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:orientation="vertical"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:id="@+id/liDialogPhoto"
    p1:background="@drawable/easydealtheme_tilesbg">
    

    我现在可以继续使用没有漂亮背景颜色的框架了!

    感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 2017-01-07
      • 1970-01-01
      相关资源
      最近更新 更多