Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:20:02+00:00 2026-05-27T17:20:02+00:00

Solved: see answer below I am sub-classing Dialog to create a dialog with a

  • 0

Solved: see answer below

I am sub-classing Dialog to create a dialog with a custom background. I have added a subclass View to the Dialog and it is drawing the bitmap background and layout correctly. But the buttons will not respond to any touch events.

I suspect the LinearLayout has to be loaded in the Dialog class, but I think I have to load it in the view class to draw on top of the bitmap.

I am totally new to Android dev, so I apologize for the question. Here is what I am doing:

public class CustomDialog extends Dialog {

private static final String TAG = "CustomDialog";
private static int layoutWidth = 640;
private static int layoutHeight = 400;

public CustomDialog(Context context) {

    super(context, android.R.style.Theme_Translucent_NoTitleBar);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    LayoutParams params = getWindow().getAttributes(); 
    params.width = LayoutParams.FILL_PARENT;
    getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

//      setContentView(R.layout.layout_dialog); // This works fine, the buttons work
    setContentView(new NewLayoutDialogView(context));
}

public static class NewLayoutDialogView extends View {

    private Drawable bg;
    public LinearLayout layout;
    private OnColorChangedListener mListener;

    public interface OnBrushChangedListener {
        void brushChanged(float radius);
    }

    NewLayoutDialogView(Context context) {  

        super(context);

        InputStream stream = getResources().openRawResource(R.drawable.dialog_bg);
        bg = NinePatchDrawable.createFromStream(stream, null);

        layout = (LinearLayout) LinearLayout.inflate(context, R.layout.layout_dialog, null);

        Button ok = (Button) layout.findViewById(R.id.ok_button);

        layout.setWillNotDraw(false);

        layout.setVisibility(View.VISIBLE);
        setVisibility(View.VISIBLE);

        layout.measure(layoutWidth, layoutHeight);
        layout.layout(0, 0, layoutWidth, layoutHeight);
    }

    @Override 
    protected void onDraw(Canvas canvas){

        if (bg != null) {
          bg.setBounds(10, 0, canvas.getWidth(), canvas.getHeight());
          bg.draw(canvas);
        }

        layout.draw(canvas);
    }
 }
}

Edit: This is how I am setting the listeners. I have to disable this code when using the View subclass as shown. But the buttons should still show the click state without a listener which they don’t.

        Dialog dialog = new ChangeLayoutDialog(getActivity());      

        Button cancel = (Button) dialog.findViewById(R.id.cancel_button);
        cancel.setTypeface(font);
        cancel.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              dialog.dismiss();
             }
          });

        Button ok = (Button) dialog.findViewById(R.id.ok_button);
        ok.setTypeface(font);
        ok.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
              dialog.dismiss();
              setCellLayout(layoutFile);
             }
          });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:20:03+00:00Added an answer on May 27, 2026 at 5:20 pm

    Instead of adding the subview class and drawing the background, all I needed to do was add:

    getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg);
    

    I guess I was just trying way too hard!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem solved: Thanks guys, see my answer below. I have a website running in
Edit: I have solved this by myself. See my answer below I have set
UPDATE: SOLVED!!! Please see the answer I added below Does anyone know if there
Update: Solved, with code I got it working, see my answer below for the
Problem solved, see below Question I'm working in Flex Builder 3 and I have
SOLVED See my answer below. Question left unchanged for anyone else who has trouble
[SOLVED (see answer below)] I am using SpreadsheetWorker API to make working with Open
edit: this is now solved, see my answer below The situation: User clicks on
UPDATE - No need to answer this now, I have solved below. Hi, I'm
(Problem solved now, see answers below) Hello, in my app I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.