使app.Dialog阴影更暗

时间:2016-03-30 08:38:59

标签: android android-layout dialog android-styles

如何使自定义app.Dialog的背景阴影更暗?

期望

enter image description here

现实

enter image description here

我尝试了什么:

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();

其中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>

1 个答案:

答案 0 :(得分:0)

尝试以下自定义课程可能会有效,

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);
    }
}

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

在onCreate()中无法正常工作onStart()