2

EDIT~ Solution found and in my response below (last response for now) but I can't mark it as the answer for question until two days from now. In the meantime, I'll leave this edit here until I can mark it correct.

Where the dialog is called:

public OnClickListener fieldListener = new OnClickListener() {
    public void onClick(View v) {
        FragmentManager fm = getSupportFragmentManager();
        switch (v.getId()) {
        case (0) :

        ChooseDialog ageDialog = new ChooseDialog("Age", ageEditText, act);
        ageDialog.show(fm, "fragment_edit_name");

The Dialog:

public class ChooseDialog extends DialogFragment implements DialogInterface.OnClickListener, OnMultiChoiceClickListener {

public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View dialogLayout = inflater.inflate(R.layout.dialog, null);

        AlertDialog.Builder builder;
        switch (editText.getId()) {
        case (0) :
            ListView list = (ListView) dialogLayout.findViewById(R.id.listView1);
        list.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist, 
                activity.getResources().getStringArray(R.array.ageArray)));
        list.setBackgroundColor(00000000);
        builder = new AlertDialog.Builder(activity);
        builder.setTitle(type);
        builder.setNegativeButton("Cancel", this);
        builder.setView(dialogLayout);
        /* builder.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist, 
                    activity.getResources().getStringArray(R.array.ageArray)), 
                    new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    editText.setText(activity.getResources().getStringArray(R.array.ageArray)[which]);
                }} 
                );*/
        return builder.create();

Dialog.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView1"
    android:background="#00000000"
    android:cacheColorHint="#00000000"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

DialogList.xml (just the textview for the adapter):

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingLeft="6dip"
    android:textColor="@color/androidBlue"
    android:paddingRight="10dip"
    android:layout_weight="1"
    android:textAppearance="?android:attr/textAppearanceLarge" />

enter image description here

Davek804
  • 2,804
  • 4
  • 26
  • 55
  • Have you tried mucking around with the `Dialog`'s window, either via code or a style? There's a couple of background-related options you can change. Several are mentioned in [this answer](http://stackoverflow.com/a/9127743/1029225). – MH. Jun 05 '12 at 19:40

3 Answers3

2

Try

list.setBackgroundColor(Color.TRANSPARENT);

EDIT:

While browsing few issues of ICS, I came across this and in my opinion I see that this might be a issue with ICS. Thought this issue is not related to the question but it shows that the developer has a problem setting the background.

Corrections are always welcome.

Sana
  • 9,895
  • 15
  • 59
  • 87
  • No dice, same result as with the 0's, the background of the dialog as well as the list is still ICS grey. – Davek804 Jun 05 '12 at 17:40
  • In your textview try android:background="@null" – Sana Jun 05 '12 at 17:44
  • Still no change with dialoglist textview's background = @null :/ – Davek804 Jun 05 '12 at 17:46
  • Can you post a screenshot of the dialog with listview once! I don't seem to find any problem with the code! – Sana Jun 05 '12 at 17:53
  • Edited a screenshot into the original post, it's running on ICS GNexus - looks just the same on an ICS emu, testing on Ginger now. (Pic has all the code you asked for in it) – Davek804 Jun 05 '12 at 18:01
  • This just in: it's properly transparent on my Ginger emu. Any ideas? – Davek804 Jun 05 '12 at 18:03
  • I believe something is wrong with ICS, I found a problem closer to yours which has been filed in as a bug http://code.google.com/p/android/issues/detail?id=19510 – Sana Jun 05 '12 at 18:07
  • Sana, that bug is a bit unrelated, but also rather similar. I think it may indeed be the issue I'm facing. If you'll edit this into your main answer, I'll vote you correct in a couple hours if no one else comes along with a miracle. – Davek804 Jun 05 '12 at 18:14
  • I get a feeling there is another Viewgroup between the Window and the builder.setView(MyView) view. I can change the window background (dialog.getWindow().setBackgroundDrawable) and I can of course change the MyView. But if you add a 9-patch with padding to the window background, you'll see that it extends outside the other views and it is transparant in this area. I think I need to get a reference to the bottom viewgroup of the dialog and set it's color to transparent... – Jacob L Aug 10 '13 at 12:13
2

My solution: change the AlertDialog.Builder constructor to use the one that takes Context, Theme:

builder = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(activity) : 
        new AlertDialog.Builder(activity, android.R.style.Theme_Translucent);

This makes sure it loads transparent on Ginger (via the lines in XML for transparent); and Translucent on ICS. The main problem is that the dialog positive and negative buttons do not match my UI. I'll be developing a solution there in the coming days.

Another issue is using builder.setMultiChoiceItems(), null, this); instead of a list. This makes it have an all white background on the entire dialog area. I'm hoping to uncover a theme method here as well, but other than this, all of my dialogs look the way I want now :P

Solution found here: https://stackoverflow.com/a/8687164/1231943

Community
  • 1
  • 1
Davek804
  • 2,804
  • 4
  • 26
  • 55
1

and for XML :

android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
  • Still transparent on Ginger, grey on ICS. I believe Sana above may have found the problem with an ICS bug. – Davek804 Jun 05 '12 at 18:10
  • yup may be. but please try once with removing list.setBackgroundColor(); line from java and set list and textview both bg color transparent....... – Dheeresh Singh Jun 05 '12 at 18:13
  • still no luck, list and textview transparent, no java changes to background at all. Ginger still looks fine with that, but ICS is still grey. – Davek804 Jun 05 '12 at 18:16
  • Excellent, thanks, I'll be looking for answers myself for the next couple of hours. Consider starring the issue that Sana linked! – Davek804 Jun 05 '12 at 18:20