c0dehunter
c0dehunter

Reputation: 6150

Android: Dialog background on emulator and my phone are different color

This is the dialog on the emulator:

emulator

And this is on my phone:

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.

//EDIT: Here is my 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();

Upvotes: 0

Views: 3806

Answers (3)

edthethird
edthethird

Reputation: 6263

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. 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. Look at http://developer.android.com/reference/android/R.style.html and check out any of the values defined as 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. For example, Android.R.style.Theme defaults to a solid black background.

And lastly, this might not be worth the effort. While Android Fragmentation is a pain in the butt, sometimes we have to embrace it. 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.

Upvotes: 1

RasTheDestroyer
RasTheDestroyer

Reputation: 1764

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

Upvotes: 1

Matthew Walton
Matthew Walton

Reputation: 9959

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. 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? 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.

Upvotes: 0

Related Questions