2015-04-27 27 views
0

我想基於這個代碼DialogFragment實現AlertDialog:如何使用AlertDialog從DialogFragment中刪除奇怪的邊框?

public class AlertDialogFragment extends DialogFragment { 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     return new AlertDialog.Builder(getActivity()) 
       .setTitle("title") 
       .setMessage("message") 
       .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

        } 
       }) 
       .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 

        } 
       }) 
       .create(); 
    } 
} 

它運作良好,但我避開AlertDialog一個奇怪的白色邊框:

enter image description here

如何刪除此邊界(最好以編程方式)?

UPDATE:我styles.xml包含此代碼:

<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light"> 
    <item name="android:alertDialogTheme">@style/MyDialogTheme</item> 
</style>   

<style name="MyDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog"></style> 

當我刪除<item name="android:alertDialogTheme">@style/MyDialogTheme</item>行,這個問題消失。但我需要這一行,因爲我想自定義AlertDialog。如何解決這種風格?

+0

能否請您發佈您的代碼,你正在使用這個'對話框Fragment'? @PartWell – Pooja

+0

@Pooja,我用代碼'new AlertDialogFragment()。show(getFragmentManager(),「TAG_HERE」);'調用它。 – BArtWell

+0

已經回答 http://stackoverflow.com/questions/2644134/android-how-to-create-a-dialog-without-a-title – Don

回答

0

我剛剛檢查過你的代碼,但沒有得到任何問題。 我調用類像

package com.example.test; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.Dialog; 

import android.content.DialogInterface; 
import android.os.Bundle; 
import android.support.v4.app.DialogFragment; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
import android.widget.Toast; 

public class A extends FragmentActivity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 



     AlertDialogFragment al=new AlertDialogFragment(); 
     FragmentManager fm = getSupportFragmentManager(); 
     al.show(fm, "test"); 


    } 


class AlertDialogFragment extends DialogFragment { 
     @Override 
     public Dialog onCreateDialog(Bundle savedInstanceState) { 
      return new AlertDialog.Builder(getActivity()) 
        .setTitle("title") 
        .setMessage("message") 
        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 

         } 
        }) 
        .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 

         } 
        }) 
        .create(); 
     } 
    } 

} 
+0

使用新的支持庫 http://developer.android.com/reference/android/support/v7/app/AlertDialog.html –

+0

我更新問題。這裏是關於問題的新事實。 – BArtWell