1

I want to do the following (paint incoming):

enter image description here

As you can see, the dialog is in the middle of the screen, with a custom View.

However, I want to user be able to click "behind" the dialog, and never dismiss the dialog.

I did the following implementation (DialogFragment):

**
 * Triggered when the Dialog is created.
 *
 * @param savedInstanceState - Bundle containing saved information.
 *
 * @return Dialog ready to be shown.
 */
@Override
public Dialog onCreateDialog( Bundle savedInstanceState )
{
    Dialog dialog = new Dialog( context );

    setCancelable( false );

    return dialog;
}

@Override
public void onCreate( Bundle savedInstanceState )
{
    super.onCreate( savedInstanceState );

    setStyle( STYLE_NO_INPUT, R.style.launcherDialog );
}

This is generating the following:

enter image description here

This is almost correct, now I want to do two things:

  • Add custom View
  • Remove the gray background generated from dialog.

So to add a custom view, I did the following in onCreateDialog:

LayoutInflater inflater = LayoutInflater.from( context )
View progressbarLayout = inflater.inflate( R.layout.launcher_dialog_view, null );
dialog.setContentView( progressbarLayout );

But I get this Exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{SearchActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

And anyways, I still have missing how can I remove the gray background generated by the DialogFragment.

Tips are soooo appreciated. I've been stuck on this for so many hours.

Edit: Oh, and the layout is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/launcher_ad_holder"
    android:layout_height="150dp"
    android:layout_width="150dp"
    android:background="@android:color/transparent">


    <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="New RadioButton"
            android:id="@+id/radioButton" android:layout_centerVertical="true" android:layout_alignParentRight="true"/>
</RelativeLayout>

And the styles:

<resources>
<style name="launcherDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:gravity">bottom</item>
</style>

Reinherd
  • 5,476
  • 7
  • 51
  • 88
  • you can refer to this link http://stackoverflow.com/questions/20258730/custom-dialog-with-close-button/20258862#20258862 – Ravneet Singh Dec 17 '13 at 12:08
  • You can't interact with what's behind a displayed dialog, so you probably need to fake a view that look like a dialog. – Kai Dec 17 '13 at 12:11
  • @Kai Are you sure? Because I'm actually interacting with the editText you can see in the paint. And I can type things and press search. The only issue is that I don't know how to add a customView (without crashing) and how to remove that gray background – Reinherd Dec 17 '13 at 12:12
  • @SergiCastellsaguéMillán Ahh I guess it's why you are using STYLE_NO_INPUT, but wouldn't that make your dialog items non-clickable? – Kai Dec 17 '13 at 12:21
  • If you want to remove the background dim effect, check out this question: http://stackoverflow.com/questions/13822842/dialogfragment-with-clear-background-not-dimmed – npace Dec 17 '13 at 12:24

4 Answers4

0

use this before your setcontentView()

 requestWindowFeature(Window.FEATURE_NO_TITLE);
Vaibhav Agarwal
  • 4,499
  • 3
  • 19
  • 20
  • requestFeature() must be called before adding content – Reinherd Dec 17 '13 at 12:09
  • yeah thats what i am asking you to do inside your dialog method use dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); – Vaibhav Agarwal Dec 17 '13 at 12:11
  • Well that's what I did, and it's still crashing. I added that in onCreateDialog: `Dialog dialog = new Dialog( context ); dialog.requestWindowFeature( Window.FEATURE_NO_TITLE ); //more code [....]` – Reinherd Dec 17 '13 at 12:12
0

Okay. I answer myself. For the double question, I just have an answer:

  1. For CustomView, we've to override method onCreateView and inflate the view there:

    @Override
    public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
    {
        return inflater.inflate( R.layout.launcher_dialog_view, null );
    }
    

However, still missing the part of removing the gray background.

Actual situation:

enter image description here

Reinherd
  • 5,476
  • 7
  • 51
  • 88
0

Try this to remove the background

Window dialogWindow = getDialog().getWindow();

dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Kuffs
  • 35,581
  • 10
  • 79
  • 92
0

Try this

 @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.0f;
        windowParams.flags |= WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        window.setAttributes(windowParams);
    }