2015-12-17 3 views
2

Я работаю с 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(); 

} 

Пожалуйста, дайте мне совет для этого. Спасибо!

+1

Попробуйте установить фон прозрачным и дизайн вашего диалога, как, как вы хотите yourcustomdialog.getWindow() setBackgroundDrawable ( \t \t \t \t нового ColorDrawable (android.graphics.Color.TRANSPARENT)). – Madhu

+0

Я уже установил его, но он не меняет цвет –

+0

О, в этом случае вы пытались установить диалоговую тему как андроид.R.style.Theme_Light – Madhu

ответ

2

Используйте эти строки кода, чтобы удалить границу

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

Или использовать эти простые строки кода для него

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

Большое спасибо. Второй ответ хорош. Я стараюсь сначала, но это не меняется –

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); 
+0

Спасибо, но я не могу изменить цвет –

0

Попробуйте какой-то один путь из ниже

отдавания прозрачный для диалога

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

} 

2), применяя стиль диалога

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

Добавить стиль к примеру из alertdialog строитель

AlertDialog.Builder(activity,R.style.DialogTransparentStyle); 
Смежные вопросы