2012-11-09 5 views
2

내가 제목 표시 줄이없는 사용자 정의 대화 상자를 만들려고하고 나는 여기에 다음과 같은사용자 정의 대화 상자가

propDiag = new Dialog(this); 
propDiag.requestWindowFeature(Window.FEATURE_NO_TITLE); 
propDiag.setContentView(R.layout.property_daig); 

을 수행하여 SO 제안을 다음 내 XML의 일부까지 내 레이아웃을 어지럽히

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:background="@drawable/background" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:orientation= "horizontal"> 
     <LinearLayout android:layout_width="wrap_content" 
      android:layout_height="fill_parent" android:orientation= "vertical" android:layout_weight="1" > 

        //COUPLE OF buttons 

     </LinearLayout> 
     <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" ></View> 
     <LinearLayout android:layout_width="wrap_content" 
      android:layout_height="fill_parent" android:orientation= "vertical" android:layout_weight="1" > 
         //COUPLE OF buttons 
      </LinearLayout> 
    </LinearLayout> 

내 레이아웃과 모든 것을 엉망으로되는 문제가 최대 오른쪽으로 밀려 난 requestWindowFeature없이 그것을 할

왼쪽 도착 후 모든 t을 제외하고 중대하다 그는 나타나는 제목!.

누구든지 해결책을 제안하고 추천 할 수 있습니까? 감사합니다.

답변

0
Try this  

      final Dialog dialog = new Dialog(context); 
        dialog.getWindow(); 
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        dialog.setContentView(R.layout.custom_dialog); 

        TextView customText = (TextView)dialog.findViewById(R.id.customDialogTitletext); 
        customText.setText(text); 
        customText.setTypeface(tf); 
        Button btnOk = (Button) dialog.findViewById(R.id.buttonOk); 
        btnOk.setOnClickListener(new OnClickListener() { 
         @Override 
         public void onClick(View arg0) { 
          dialog.dismiss(); 
         } 
        }); 
        dialog.show(); 

       } 

문제가 해결되었는지 여부를 알려주세요.

+0

나는 당신이 언급 한이 ok 단추와 제목 ID가 없기 때문에 이것이 내 게시 된 코드와 어떻게 관련이 있는지 잘 모르겠습니다. 게다가 제목 기능이없는 창을 요청하여 사용했던 것과 동일한 코드를 사용했습니다. 플러스 대화 상자. Getwindow는 그 자체로 아무 것도하지 않습니다. – Snake

+0

대화 상자에서 제목을 지울 수있는 유일한 방법입니다. titleId 및 button은 사용자 정의 대화 상자 레이아웃에 있습니다. –

3

코드 아래 참조 :

나는 배경 이미지를 가지고 있지 않지만, 그냥 아이콘 이미지를 넣어하고 아래의 코드를 실행합니다.

출력 화면을 첨부했습니다.

코드 :

Button test = (Button) findViewById(R.id.button1); 

    test.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      final Dialog dialog = new Dialog(MainActivity.this); 
      dialog.getWindow(); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.property_daig); 

      dialog.show(); 

     } 

    }); 

출력 :

enter image description here

그것은 당신을 도울 것입니다 바랍니다.

코딩 즐기기. :)

관련 문제