2016-03-30 3 views
-1

Wie machen Sie Hintergrund Schatten von benutzerdefinierten app.Dialog dunkler?Machen Sie app.Dialog Schatten dunkler

Erwartung:

enter image description here

Reality:

enter image description here

Was ich versucht:

1) MyDialog dialog = new MyDialog (mContext); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); dialog.show();

2) MyDialog dialog = new MyDialog (mContext, R.style.NewDialog); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); dialog.show();

wo R.style.NewDialog.

<!-- This style removes shadow but I need to make it darker.--> 
<!-- Don't know which parameter needed to change for that--> 
<style name="NewDialog"> 
    <item name="android:windowFrame">@null</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowTitleStyle">@null</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
    <item name="android:backgroundDimEnabled">false</item> 
    <item name="android:background">@android:color/transparent</item> 
</style> 

Antwort

0

folgende benutzerdefinierte Klasse ausprobieren Arbeit sein kann,

import android.app.AlertDialog; 
import android.app.Dialog; 
import android.app.DialogFragment; 
import android.content.DialogInterface; 
import android.os.Bundle; 
import android.view.Window; 

import com.stackexmples.R; 

/** 
* Created by windws on 30-Mar-16. 
*/ 
public class AlertDFragment extends DialogFragment { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     return new AlertDialog.Builder(getActivity()) 
       // Set Dialog Icon 
       .setIcon(R.drawable.androidhappy) 
         // Set Dialog Title 
       .setTitle("Alert DialogFragment") 
         // Set Dialog Message 
       .setMessage("Alert DialogFragment Tutorial") 

         // Positive button 
       .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         // Do something else 
        } 
       }) 

         // Negative Button 
       .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         // Do something else 
        } 
       }).create(); 
    } 
    @Override 
    public void onStart() { 
     super.onStart(); 
     Window window = getDialog().getWindow(); 
     window.setBackgroundDrawableResource(android.R.color.transparent); 
    } 
} 

Fenster Fenster = getDialog() getWindow(); window.setBackgroundDrawableResource (android.R.color.transparent);

nicht in onCreate arbeiten() es onStart()

+0

Keine Änderungen arbeiten. Scheint wie das gleiche wie in 1) 'dialog.getWindow(). SetBackgroundDrawable (neue ColorDrawable (Color.BLACK));' – AnZ

+0

Wie zeige ich diesen Dialog an? – AnZ

+0

AlertFragment alertDFragment = new AlertDFragment(); newFragment.show (getFragmentManager(), "Dialog"); –