更改对话框android的颜色

时间:2015-12-17 04:56:01

标签: android dialog

我正在使用Android Dialog

enter image description here

我想在此对话框中删除两种黑色。但似乎我不能这样做。

这是我的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_loading_background_white">
<ImageView
    android:src="@drawable/ic_logo"
    android:layout_width="230dp"
    android:layout_height="64dp"
    android:layout_marginTop="10dp"
    android:scaleType="centerCrop"
    android:contentDescription="@string/app_name"
    android:layout_gravity="center_horizontal"/>
<EditText
    android:id="@+id/username"
    android:inputType="text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:layout_marginBottom="4dp"
    android:hint="Enter username" />

</LinearLayout>

创建对话框时这是我的代码。

public static void showDialog(Activity activity, int layout, final IOnOkClicked cb, final IOnCancelClicked cb2) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    // Get the layout inflater
    LayoutInflater inflater = activity.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(layout, null))
            // Add action buttons
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (cb != null) {
                        cb.onClick();
                    }
                }
            })
            .setCancelable(false);

    if (cb2 != null) {
        builder.setNegativeButton(activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                cb2.onClick();
            }
        });
    }
    builder.create().show();

}

请给我建议这样做。谢谢!

4 个答案:

答案 0 :(得分:2)

使用这些代码行删除边框

 AlertDialog alertbox = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT);

或者使用这些简单的代码行

public static void showDialog(Activity activity, int layout, final IOnOkClicked cb, final IOnCancelClicked cb2) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    // Get the layout inflater
    LayoutInflater inflater = activity.getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(layout, null))
            // Add action buttons
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (cb != null) {
                        cb.onClick();
                    }
                }
            })
            .setCancelable(false);

    if (cb2 != null) {
        builder.setNegativeButton(activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                cb2.onClick();
            }
        });
    }
 final AlertDialog dialog= dialogBuilder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.show();

}

答案 1 :(得分:0)

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

        LayoutInflater inflater = this.getLayoutInflater();
        View dialogView = inflater.inflate(R.layout.exitdialog, null);
        dialogBuilder.setView(dialogView);
        final AlertDialog alertDialog = dialogBuilder.create();


        alertDialog.show();
        alertDialog.getWindow().setBackgroundDrawableResource(
                android.R.color.transparent);

答案 2 :(得分:0)

从下面尝试任何一种方式

给对话框透明

<style name="DialogTransparentStyle">
    <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>
将样式应用于对话框

2)

AlertDialog.Builder(activity,R.style.DialogTransparentStyle);

将样式添加到alertdialog builder的实例

// include gulp
var gulp = require('gulp'); 
var sass = require('gulp-sass');

var minifyCss = require('gulp-minify-css');


//gulp sass

gulp.task('sass', function () {
  gulp.src('./scss/main.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(gulp.dest('./css'));
});

// gulp.task('minify-css', function() {
//   return gulp.src('css/*.css')
//     .pipe(minifyCss({compatibility: 'ie8'}))
//     .pipe(gulp.dest('css'));
// });

gulp.task('sass:watch', function () {
  gulp.watch('./scss/main.scss', ['sass']);
});

答案 3 :(得分:0)

相关问题