y ramesh rao
y ramesh rao

Reputation: 3004

Android Custom Dialog Class Title Problems

public class MessageDisplayDialog extends Dialog implements OnClickListener

{

    public MessageDisplayDialog(Context context, String title, String message)
    {
        super(context);
        setTitle(title);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.color.default_text_color);
        Log.v(getClass().getSimpleName(), "MessageDisplayDialog");
        LinearLayout objLinearLayout = new LinearLayout(context);
        LinearLayout objButtonLayout = new LinearLayout(context);

        TextView objMesaageView = new TextView(context);
        objMesaageView.setText(message);
        objMesaageView.setTextColor(Color.WHITE);
        objMesaageView.setGravity(Gravity.CENTER_HORIZONTAL);
        objMesaageView.setPadding(0, 0, 0, 10);

        Button okButton = new Button(context);
        okButton.setText(" OK ");
        okButton.setOnClickListener(this);
        okButton.setWidth(100);
        objButtonLayout.addView(okButton);
        objButtonLayout.setGravity(Gravity.CENTER_HORIZONTAL);
        objButtonLayout.setPadding(0, 5, 0, 0);
        objButtonLayout.setBackgroundColor(Color.LTGRAY);

        objLinearLayout.setOrientation(LinearLayout.VERTICAL);
        objLinearLayout.addView(objMesaageView);
        objLinearLayout.addView(objButtonLayout);

        setContentView(objLinearLayout);
        //LayoutParams param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        //this.addContentView(objLinearLayout, param);
    }

    public void onClick(View v)
    {
        this.dismiss();
    }
}

But the Dialog is not showing bar below the Title, how to crack it.

Upvotes: 2

Views: 7975

Answers (4)

alok tiwari
alok tiwari

Reputation: 637

use two lines of code to remove dialoge title

Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);

Upvotes: 1

Stephan Tual
Stephan Tual

Reputation: 2637

This is old I know, but FYI the solution of drawing your own line on a custom dialog is not compatible with ICS.

It will display both your line and the line that ICS is now including by default. So you'd get two lines on the screen.

Upvotes: 2

Mark B
Mark B

Reputation: 200850

I think the horizontal border between the title and the message in the built in dialogs is part of AlertDialog, not the base Dialog class, although I could be totally wrong about that. Regardless, whenever I attempt to do something similar to what you are doing, that horizontal line disappears and I've never been able to get it back.

I ended up just writing my own dialog layout XML file and creating my own horizontal line using a <shape> drawable. It's actually fairly painless to create your own completely custom Dialog layouts like this, and gives you more control over the look of your dialogs.

Upvotes: 2

prasanna
prasanna

Reputation: 1917

I think your question has already been answered in this thread

Android - change custom title view at run time

please do some searching and accept answers before asking questions.

Upvotes: 3

Related Questions