• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Getting rid of screen behind Dialog?

croninberg

Newbie
Oct 24, 2016
35
5
So I've followed a tutorial on making dialog's and while it works fine, the dialog always has this white background behind it.

dialog.png


You can see it here in the image. I've tried making it transparent and stuff but it doesn't seem to work. I want it so that behind the popup will be the home screen or something else, with the dialog floating on top.

Code for dialog,
Code:
public class AlarmDialogClass extends Activity implements View.OnClickListener {

    private AlertDialog.Builder mBuilder;
    private AlertDialog mAlertDialog;
    private View mDialogView;
    private Button mOkBtn, mCancelBtn;

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

        LayoutInflater inflater = getLayoutInflater();

        // build the dialog
        mBuilder = new AlertDialog.Builder(this);
        mDialogView = inflater.inflate(R.layout.dialog_layout, null);

        mOkBtn = (Button) mDialogView.findViewById(R.id.ok);
        mCancelBtn = (Button) mDialogView.findViewById(R.id.cancel);

        mOkBtn.setOnClickListener(this);
        mCancelBtn.setOnClickListener(this);

        mBuilder.setCancelable(false);
        mBuilder.setView(mDialogView);
        mAlertDialog = mBuilder.create();
        mDialogView.setBackground(new ColorDrawable(Color.TRANSPARENT));

        mAlertDialog.show();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ok:
                mAlertDialog.dismiss();
                break;
            case R.id.cancel:
                mAlertDialog.dismiss();
                break;
        }
    }
}
 
Right I managed to get this working finally. The problem lies in the android manifest file. The AlarmDialogClass I have above needs to be set to a Dialog theme and have a singleInstance launch mode.

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.android.shnellers.dialogue"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".AlarmDialogClass"
            android:theme="@android:style/Theme.Dialog"
            android:launchMode="singleInstance" />

        <receiver android:process=":remote" android:name=".AlertDialogReceiver" />
    </application>

</manifest>

When I began using the DialogFragment, I was calling it from inside the AlarmDialogClass, so this launched the DialogDragment dialog first and when I closed it the AlarmDialogClass launched it's own dialog straight after, so was getting this second dialog.

little_dialog.png


So got rid of the DialogFragment altogether and by launching from the Activity prevents this happening.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones