출처 : 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 를 만들어 띄우면 다음과 같은 모습니다
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); 를 주어도 같은 현상이 나는지 궁금해 집니다
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 여부 설정
|
2) Dialog 호출시 배경화면이 검정색으로 바뀌는 것 막기 !
|
3) Dialog 밖을 터치 했을 경우 Dialog 사라지게 하기
mDialog.setCanceledOnTouchOutside(true); |
4) Dialog 밖의 View를 터치할 수 있게 하기 (다른 View를 터치시 Dialog Dismiss)
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
5) Dialog 자체 배경을 투명하게 하기
(new ColorDrawable(android.graphics.Color.TRANSPARENT)); |
6) Dialog Cancle시 Event 받기
|
7) Dialog Show시 Event 받기
|
8) Dialog Dismiss시 Event 받기
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
출처: 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));
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.
}