카테고리 없음

출처 : http://code.google.com/p/android4u/wiki/Dialogs

 

 Dialogs  

How to implement customized Dialog with transparent background?

If you want to display a dialog with buttons such as OK,Cancel, you can use an AlertDialog which extends the Dialog class. But the AlertDialog leaves less customization space for you to set the theme, such as a transparent background, customized background picture...(whatever, I could not find the solutions, if you know it, pls tell me, thanks.)

You can not construct an AlertDialog by using the constructor, you should use AlertDialog.Builder class to build your AlertDialog, it is very easy by

AlertDialog.Builder builder = new AlertDialog.Builder();//static inner class 
builder
.setTitle().setIcon().setMessage(); 
builder
.setPositiveButton().setNegativeButton().setNeutralButton(); 
builder
.setItems().setAdapter().setCursor().setMultiChoiceItems().setSingleChoiceItems(); 
builder
.create();

But I could not find a way to set the theme of an AlertDialog. The theme of an AlertDialog was internally used.

<style name="Theme.Dialog.Alert"> 
   
<item name="windowBackground">@android:color/transparent</item> 
   
<item name="windowTitleStyle">@android:style/DialogWindowTitle</item> 
   
<item name="windowIsFloating">true</item> 
   
<item name="windowContentOverlay">@null</item> 
</style>

While, for the public class Dialog, you can use new Dialog(Context ctx, int theme) to specify the theme you want use. The default theme for a Dialog is defined as below:

<style name="Theme.Dialog"> 
   
<item name="android:windowFrame">@null</item> 
   
<item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item> 
   
<item name="android:windowBackground">@android:drawable/panel_background</item> 
   
<item name="android:windowIsFloating">true</item> 
   
<item name="android:windowContentOverlay">@null</item> 
   
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
   
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
</style>

But you can define a theme or style in your $proj/res/values/styles.xml file and apply it to your dialog.

You can also apply the Theme.Dialog to an Activity, then the activity will appear looks like a dialog.

More details about Dialog & AlertDialog, refer the ApiDemos application. 


///////////////////////////////////////////////////////////////////////

출처:  http://escomic.net/399

기본적으로 android 에서 dialog 를 만들어 띄우면 다음과 같은 모습니다






여기서 dialog 의 기본 ui 인 title이라던가 하얀 테두리 같은것을 쓰고싶지 않을때 
초간단하게 다음과 같이 하면된다 -_-;;

requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));


이건 머..
너무 케간단해서 글로 올리기가 민망하구먼;;


LayoutInflater mInflater = getLayoutInflater();
View dialogLayout = mInflater.inflate(R.layout.dialog_notic01,(ViewGroup)findViewById(R.drawable.popup_bg));

Dialog mDialog = new Dialog(this);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mDialog.setContentView(dialogLayout);
mDialog.show();
자 이런시긍로 하는 거임.ㅋ

////////////////////////////////////////////////////////////////


출처: http://www.androidpub.com/645587

heme 를 Dialog 로 지정하면 해당 팝업 뒤에 Activity 의 Label 이 출력되는 부분이 나오는것 같더라구요

혹시 onCreate 안에 this.setVisible(false); 를 주어도 같은 현상이 나는지 궁금해 집니다
댓글
2010.08.09 17:47:01
gas
다음 추가해보세요. 어디서 본건지 기억이 안나는...
1.protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) {
2.super.onApplyThemeResource(theme, resid, first);
3.// no background panel is shown
4.theme.applyStyle(style.Theme_Panel, true);
5. 
6.}

댓글
2010.08.09 17:58:09
형태구리
이게 되는군요~그렇게 찾아도 없더니~~감사합니다.^^:
댓글
2011.07.06 15:23:23
안입
(추천: 1 / 0)
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

dialog.getWindow().

//////////////////////////////////////////////////////////////////////////////

자신이 만든 xml view 만 보이게 하기

 View popupView = View.inflate(act, R.layout.cchatpopup, null);
        

 AlertDialog _ab = new AlertDialog.Builder(act)
        .show();
       
        _ab.getWindow().setBackgroundDrawable(new ColorDrawable(0x0000ff00)); 
        _ab.setContentView(popupView);







/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//AlertDialog 뒷 투명검은 배경에 투명값 넣기

AlertDialog _ab = new AlertDialog.Builder(ba)

.setMessage("test");


//뒷 검은배경을 알파값을 넣어줄수 있다.

private void setDimBehindAlpha(float alpha)

{

if(_ab == null)

return;

_ab.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

WindowManager.LayoutParams lp = _ab.getWindow().getAttributes();  

lp.dimAmount= alpha;  

_ab.getWindow().setAttributes(lp);  

_ab.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);  

}





///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


출처: http://arabiannight.tistory.com/360


Dialog의 각종 속성들 정리 입니다.


1) Back키 눌렀을 경우 Dialog Cancle 여부 설정

 
  mDialog.setCancelable(false); // true : cancle , false : no cancle


2) Dialog 호출시 배경화면이 검정색으로 바뀌는 것 막기 !

 
  mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);


3) Dialog 밖을 터치 했을 경우 Dialog 사라지게 하기

 
  mDialog.setCanceledOnTouchOutside(true);


4) Dialog 밖의 View를 터치할 수 있게 하기 (다른 View를 터치시 Dialog Dismiss)

 
  mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,

             WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
 


5) Dialog 자체 배경을 투명하게 하기

 
  mDialog.getWindow().setBackgroundDrawable

             (new ColorDrawable(android.graphics.Color.TRANSPARENT));
 



6) Dialog Cancle시 Event 받기 

 
  mDialog.setOnCancelListener(OnCancelListener listener) 




7) Dialog Show시 Event 받기 

 
  mDialog.setOnShowListener(OnShowListener listener) 




8) Dialog Dismiss시 Event 받기 

 
  mDialog.setOnDismissListener(OnDismissListener listener) 








/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


출처: http://www.masterqna.com/android/8142/%EC%BB%A4%EC%8A%A4%ED%85%80-alertdialog-%ED%88%AC%EB%AA%85%ED%95%98%EA%B2%8C-%EB%A7%8C%EB%93%9C%EB%8A%94-%EB%B2%95




다이얼러그.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

이소스를 추가하시면 됩니다.

 

CustomDialog를 사용하시다면 onCreate()에서 

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