2012-02-16 4 views
4

'Theme.Holo.Light.Dialog'에서 상속 한 사용자 정의 테마를 작성했습니다.Android - 사용자 정의 대화 상자에 대한 사용자 정의 테마 지정 AlertDialog.Builder가 대화 상자에 내용을 래핑합니다.

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="cust_dialog" parent="@android:style/Theme.Holo.Light.Dialog"> 
</style> 
</resources> 

는 내 코드 :

private AlertDialog testDialog; 
AlertDialog.Builder testBuilder; 
LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE); 
View layout = inflater.inflate(R.layout.test_dialog, 
            (ViewGroup) findViewById(R.id.test_root)); 
testBuilder = new AlertDialog.Builder(this, R.style.cust_dialog); 
testBuilder.setView(layout); 
testBuilder.setTitle("Support"); 
testDialog = testBuilder.create(); 
testDialog.show(); 

이 대화 이내 내 대화가 발생합니다. 이 문제를 어떻게 해결할 수 있습니까?

감사합니다.

편집 ::::

이 내 test_dialog.xml 레이아웃입니다 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/test_root" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      > 


     <Button 
      android:id="@+id/test1" 
      android:layout_width="300dp" 
      android:layout_height="75dp" 
      android:text="@string/test" 

      android:gravity="center" /> 

     <Button 
      android:id="@+id/test2" 
      android:layout_width="300dp" 
      android:layout_height="75dp" 
      android:text="@string/test" 
      android:layout_below="@id/test1" 
      android:gravity="center" /> 

</RelativeLayout> 
+1

아마도'R.layout.test_dialog'에는 그 이상의 내용이 포함되어 있을까요? 'setView()': "사용자 정의보기를 대화 상자의 내용으로 설정". 거기에 전체 대화 상자 레이아웃을 추가하면 대화 상자 안에 대화 상자가 생깁니다. – zapl

+0

내 test_dialog 레이아웃 xml을 추가했습니다. 나는 거기에 버튼이 두 개 밖에 없다. – CLDev

+0

팽창 중에 지정한 루트 요소로 인해 야합니다. 그냥'View layout = inflater.inflate (R.layout.test_dialog, null);와 같이 해보십시오. 그렇지 않으면 레이아웃 자체를 팽창시킵니다. – zapl

답변

5

이 밖으로 시도.

ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.MyTheme); 
      AlertDialog.Builder builder= new AlertDialog.Builder(ctw); 
      LayoutInflater inflater = (LayoutInflater) ctw.getSystemService(LAYOUT_INFLATER_SERVICE); 
      View view = inflater.inflate(R.layout.customdialogue, 
              (ViewGroup) findViewById(R.id.layout_root)); 
+1

'ContextThemeWrapper ctw = 새로운 ContextThemeWrapper (this, R.style.MyTheme); AlertDialog.Builder builder = 새 AlertDialog.Builder (ctw);는 나를 위해이 문제를 해결했습니다. – howettl

0

은하지 usuall 문맥을 통해 레이아웃의의 Inflater를 얻기 위해 매우 중요하지만, 상황에 맞는 래퍼의 컨텍스트를 통해 ...

0

당신은 시도 할 수 있습니다 그 시점에서 조금 또한 struggeled 이

AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.layout.test_dialog); 
관련 문제