[英]Android: Dialog background on emulator and my phone are different color
This is the dialog on the emulator: 这是模拟器上的对话框:
And this is on my phone: 这是在我的手机上:
I tried setting background to my layout but then the title space and bottom space would still be this white color. 我尝试将背景设置为我的布局,但标题空间和底部空间仍然是这种白色。 How do I "repair" it?
我该如何“修理”它?
If it matters, the second picture is from MIUI ROM. 如果重要,第二张图片来自MIUI ROM。
//EDIT: Here is my layout.xml: //编辑:这是我的layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Spinner
android:id="@+id/spinner_minutes"
android:layout_width="170dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:entries="@array/timer_values"/>
<TextView
android:id="@+id/text_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/button_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner_minutes"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip">
<Button
android:id="@+id/button_set"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Set"
android:layout_marginLeft="10dip"
android:layout_marginBottom="5dip" />
<Button
android:id="@+id/button_cancel"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginRight="10dip"
android:layout_marginBottom="5dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/button_holder2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_timer"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip"
android:visibility="gone">
<Button
android:id="@+id/button_close"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Close"/>
<Button
android:id="@+id/button_cancel2"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>
I am creating the dialog this way: 我这样创建对话框:
about_dlg=new Dialog(SoundRelaxerActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.about_dialog);
about_dlg.show();
Make sure you are setting the background of the top overall layout (in this case the relative layout) 确保设置顶部整体布局的背景(在本例中为相对布局)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#c0c0c0">
The emulator is just using a different default color than your phone. 模拟器只使用与手机不同的默认颜色。 Change #c0c0c0 to whatever color you want
将#c0c0c0更改为您想要的任何颜色
This call: 这个电话:
about_dlg=new Dialog(SoundRelaxerActivity.this);
will use the system default theme. 将使用系统默认主题。 Every hardware manufacture develops their own custom system default themes.
每个硬件制造商都开发自己的定制系统默认主题。 For example, the default
Button
might look different on Motorola Blur than it does on HTC Sense. 例如,默认
Button
在Motorola Blur上可能与在HTC Sense上看起来不同。 If you want to build a dialog, with a custom theme, use this call instead: 如果要使用自定义主题构建对话框,请改用此调用:
about_dlg = new Dialog(context, android.R.style.Theme);
BUT android.R.style.Theme
might not be what you want. 但是
android.R.style.Theme
可能不是你想要的。 Look at http://developer.android.com/reference/android/R.style.html and check out any of the values defined as Theme_ 查看http://developer.android.com/reference/android/R.style.html并查看定义为Theme_的任何值
AND A HEADS UP: 和一个抬头:
This might not work out of the box. 这可能不是开箱即用的。 You are going to have to modify your layout xml file to have the appropriate styles relevant to the theme you choose.
您将不得不修改布局xml文件以使其具有与您选择的主题相关的适当样式。 For example,
Android.R.style.Theme
defaults to a solid black background. 例如,
Android.R.style.Theme
默认为纯黑色背景。
And lastly, this might not be worth the effort. 最后,这可能不值得努力。 While Android Fragmentation is a pain in the butt, sometimes we have to embrace it.
虽然Android碎片是一个痛苦的屁股,有时我们必须接受它。 The user is used to the default settings of the device-- for example if every dialogue on their phone is white but yours is black, they might be jarred by this.
用户习惯于设备的默认设置 - 例如,如果手机上的每个对话都是白色但你的手机是黑色的,那么它们可能会受到震动。 That is a weak example, but hopefully you get the point.
这是一个很弱的例子,但希望你明白这一点。
I know on Android 4 you can ask for the default Holo theme for your application which eliminates this possibility as Holo HAS to be present on an Android 4 system. 我知道在Android 4上你可以为你的应用程序要求默认的Holo主题,这消除了这种可能性,因为Holo HAS将出现在Android 4系统上。 Prior to that, all you've got is the default theme which could be anything at all.
在此之前,你所拥有的只是默认主题,可以是任何东西。
The question is, why is your text white on white on MIUI? 问题是,为什么你的文字在MIUI上是白色的? Are you setting that explicitly?
你明确地设置了吗? If you aren't, then I would consider that you're seeing a bug in the theme rather than your app because if the theme author has made these dialogs white then the default text colour should surely be dark or else every app would suffer the same problem.
如果你不是,那么我会认为你在主题而不是你的应用程序中看到了一个错误,因为如果主题作者将这些对话框设置为白色,那么默认的文本颜色应该是黑暗的,否则每个应用程序都会受到影响同样的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.