简体   繁体   English

Android自定义对话框Textview和背景颜色

[英]Android Custom Dialog Textview and Background Color

I have a custom DialogPreference Dialog that has its layout set out in a relativelayout that contains the following: 我有一个自定义的DialogPreference对话框,其布局设置在包含以下内容的relativelayout中:

  • Checkbox 复选框
  • Textview 的TextView
  • Text Field 文本域

This is fine in Android 4.0+, because the theme we are using is Theme.Light so the background color of the dialog is white and the default text is black for the Checkbox label and textview. 这在Android 4.0+中很好,因为我们使用的主题是Theme.Light,因此对话框的背景颜色为白色,Checkbox标签和textview的默认文本为黑色。 However, in 2.3.3, the background color is dark grey so it becomes hard to see the text... the theme is still Theme.Light however. 但是,在2.3.3中,背景颜色为深灰色,因此很难看到文本......主题仍然是Theme.Light。

I thought that making a custom dialog would be necessary for this because the checkbox enable/disables the text field. 我认为为此需要制作自定义对话框,因为复选框启用/禁用文本字段。 At the moment, I'm making the background color of the relativelayout for this Dialog white... but I don't really like this solution as there maybe cases where some other phones on 2.3.3 may not have white as the default dialog background... 目前,我正在为这个Dialog白色制作相对布局的背景颜色......但是我真的不喜欢这个解决方案,因为在某些情况下2.3.3上的其他手机可能没有白色作为默认对话框背景...

Is there a cleaner way to fix this problem? 有没有更清洁的方法来解决这个问题?

I notice this person has the same problem: Custom Support Dialog Fragment text is the wrong color 我注意到这个人有同样的问题: 自定义支持对话框片段文本是错误的颜色

Another with the problem : Android: Issue with showing dialog from Theme.Light activity 问题的另一个: Android:从Theme.Light活动显示对话框的问题

EDIT: Attached screenshot. 编辑:附加截图。 This is what it looks like on LG Optimus 2X running 2.3.3. 这就是运行2.3.3的LG Optimus 2X的样子。 On my co-worker's samsung galaxy which runs 2.3.3 also, the background is even darker so you can hardly see the text. 在我同事的三星星系中也运行2.3.3,背景更暗,所以你几乎看不到文字。

在此输入图像描述

You could make custom dialog theme in style files , such as: 您可以在样式文件中创建自定义对话框主题,例如:

less than API 11:

<style name="MyDialogTheme" parent="android:Theme.Light" >

API 11 and forward:

<style name="MyDialogTheme" parent="android:Theme.Holo.Dialog" >

then use "MyDialogTheme" in your Fragment dialog: 然后在Fragment对话框中使用“MyDialogTheme”:

... ...
ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), R.style.MyDialogTheme);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
... ...

hope this help. 希望这个帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM