Programmer
Programmer

Reputation: 5400

Dialog box not renderd properly in android

i have a dialog box, but some how there is an unknown background image. How can i remove that image. Please guide me.

enter image description here

Upvotes: 0

Views: 87

Answers (2)

K_Anas
K_Anas

Reputation: 31466

You have to extends Dialog Class, build your xml File for your dialog something like

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Do you Want to bookmark?" 
        android:gravity="center"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No" />

        <Button
            android:id="@+id/button_yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Yes" />

    </LinearLayout>

</LinearLayout>

of course you can make some customization

for your custom dialog class you can do like this

public class CustomizeDialog extends Dialog implements OnClickListener {
 Button okButton;

 public CustomizeDialog(Context context) {
  super(context);

  /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
  requestWindowFeature(Window.FEATURE_NO_TITLE);


  setContentView(R.layout.main);
  yesButton = (Button) findViewById(R.id.button_yes);
  yesButton.setOnClickListener(this);

  noButton = (Button) findViewById(R.id.button_no);
  noButton.setOnClickListener(this);

 }

 @Override
 public void onClick(View v) {
        switch(v.getId()){

        case R.id.button_yes: 
             dismiss();
             //doSomething
             break;
            case R.id.button_no:
            dismiss();
            //doSomethingElse
            break;

 }

}

Hope this will help you you have to post your code to figure out why these background box appear for you but acting like i mention should resolve the problem for you

Upvotes: 2

user
user

Reputation: 87064

That is probably happening because you use the standard AlertDialog and set a content view + no title(although you don't set a title the space for it will remain in the dialog).

Extend the Dialog class instead and build your dialog like you want. Also if you want to use your own background for the Dialog then implement a theme that extends Theme.Dialog and override:

<item name="android:windowBackground">@android:drawable/panel_background</item>

with your own drawable.

Upvotes: 1

Related Questions