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

时间:2013-03-24 21:12:44

标签: android text colors dialog

我有一个自定义DialogPreference对话框,其布局设置在包含以下内容的relativelayout中:

  • 复选框
  • Textview
  • 文字字段

这在Android 4.0+中很好用,因为我们使用的主题是Theme.Light,因此对话框的背景颜色为白色,而Checkbox标签和textview的默认文本为黑色。但是,在2.3.3中,背景颜色为深灰色,因此很难看到文字......主题仍然是Theme.Light。

我认为为此需要制作自定义对话框,因为复选框启用/禁用文本字段。目前,我正在为这个Dialog白色制作相对布局的背景颜色......但是我真的不喜欢这个解决方案,因为在某些情况下2.3.3上的其他手机可能没有白色作为默认对话框背景...

有没有更清洁的方法来解决这个问题?

我注意到这个人有同样的问题:Custom Support Dialog Fragment text is the wrong color

另一个有问题:Android: Issue with showing dialog from Theme.Light activity

编辑:附上截图。这就是运行2.3.3的LG Optimus 2X的样子。在我同事的三星星系中也运行2.3.3,背景更暗,所以你几乎看不到文字。

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以在样式文件中创建自定义对话框主题,例如:

less than API 11:

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

API 11 and forward:

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

然后在Fragment对话框中使用“MyDialogTheme”:

... ...
ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), R.style.MyDialogTheme);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
... ...
希望这有帮助。

相关问题