2016-12-26 16 views
2

AlertDialogue 테마 또는 변경 배경색을 설정하고 싶습니다.경고 대화 상자 배경 테마/색상

기본 테마가 있지만 다른 버전이 있으므로 다른 테마로 바뀌므로 모든 버전에서 수정하고 싶습니다.

또는 단순히 내가 여기 변경해야하는 위치 코드를 알려주세요 게시하지 마십시오 흰색

@NonNull 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     final SimpleAdapter adapter = new SimpleAdapter(getContext(), imagesWithNames, R.layout.lib_dialog_image, 
       new String[]{"name", "imageID","Spacing"}, new int[]{R.id.text1, R.id.image1,R.id.spacing}); 
     return new AlertDialog.Builder(getContext()).setAdapter(adapter, 
       new DialogInterface.OnClickListener() { 
        @Override 
        public void onClick(DialogInterface dialogInterface, int i) { 
         ((PlaceCallActivity) getContext()).OnSelected(WithNamesFragment.this.getClass(), (int) ((HashMap<String, Object>) adapter.getItem(i)).get("imageID")); 
        } 
       }).setCancelable(true).setTitle("PICK YOUR AVATAR").setNegativeButton("Cancel",new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       dialog.dismiss(); 
      } 
     }).create(); 
    } 

등의 배경 색상을 변경할 수 있습니다.

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom)); 

참고 : 위의 라인은 그것을 할 것입니다하지만 난에 대한 스타일을 제공한다 어디 있는지 알고 싶어AlertDialogue

enter image description here

+0

아직도 해결책을 찾고 있습니까? –

+0

예 아직 찾지 못했습니다! – SamH67

+0

이것을 참조하십시오. http://stackoverflow.com/questions/2422562/how-to-change-theme-for-alertdialog –

답변

5

styles.xml 파일에 스타일을 만듭니다. ContextThemeWrapper 클래스 생성자에 현재 클래스의 컨텍스트와 스타일을 통과

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(NewCase.this, R.style.AlertDialogCustom)); 

여기에 다음과 같이 빌더를 사용하여

<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog"> 
     <item name="android:textColor">@color/White</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:headerDividersEnabled">true</item> 
     <item name="android:typeface">normal</item> 
     <item name="android:background">@color/colorPrimaryDark</item> 
    </style> 

다음 만들기를 Alert Dialog.

+0

먼저보고 내가해야 할 일을 말해줘. 내 반환 대화 상자에이 작업을 추가 할 수 없다. Ankit Shah가 올바르게 처리하고 있지만 문제가있다. – SamH67

+0

@ SamH67 정확히 무엇을 원하니? 그럼 내가 너를 도울 수있어. –

+0

코드를 추가 할 수 없기 때문에 내 방식대로하고 싶습니다. 내 코드를보고 추가하는 방법을 알려주지 만 시도하기 전에 시도하십시오. 이미이 문제를 게시하기 전에 이미이 문제를 시도했기 때문에 이미이 사실을 알고 있지만 그 return 문 내에서 테마를 변경할 수 있습니다. – SamH67

2
당신은 대화 스타일 내부 고해상도/값/스타일을 추가해야

.xml. 아래처럼.

<style name="MyDialog" parent="@android:style/Theme.Holo.Light.Dialog"> 
     <item name="android:background">@color/white</item> 
    </style> 

은 또는 당신은 또한 다음과 같이 배경색을 변경 :

편집 : 다음과 같이

getWindow().setBackgroundDrawableResource(R.color.white); 
+0

getWindow를 확인할 수 없습니다. – SamH67

+0

@ SamH67 내 대답이 업데이트되었습니다. –