本文整理汇总了Java中android.view.Window.setContentView方法的典型用法代码示例。如果您正苦于以下问题:Java Window.setContentView方法的具体用法?Java Window.setContentView怎么用?Java Window.setContentView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Window
的用法示例。
在下文中一共展示了Window.setContentView方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beginCameraDialog
import android.view.Window; //导入方法依赖的package包/类
final void beginCameraDialog() {
DIALOG.show();
final Window window = DIALOG.getWindow();
if (window != null) {
window.setContentView(R.layout.dialog_camera_panel);
window.setGravity(Gravity.BOTTOM);
window.setWindowAnimations(R.style.anim_panel_up_from_bottom);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//设置属性
final WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(params);
window.findViewById(R.id.photodialog_btn_cancel).setOnClickListener(this);
window.findViewById(R.id.photodialog_btn_take).setOnClickListener(this);
window.findViewById(R.id.photodialog_btn_native).setOnClickListener(this);
}
}
示例2: show
import android.view.Window; //导入方法依赖的package包/类
public AlertDialog show(Context context) {
dialog = new AlertDialog.Builder(context).create();
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.dialog_date_time);
window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
//window.setWindowAnimations(R.style.in_left_out_right_style);
window.setBackgroundDrawableResource(R.color.transparent);
datePicker = (DatePicker) window
.findViewById(R.id.date_time_datePicker1);
datePicker.setCalendarViewShown(false);
timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
but_ok.setOnClickListener(this);
return dialog;
}
示例3: initDialog
import android.view.Window; //导入方法依赖的package包/类
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
//contentLayout.setFitsSystemWindows(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(false);//触摸屏幕取消窗体
dialog.setCancelable(false);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
示例4: show
import android.view.Window; //导入方法依赖的package包/类
/**
* DialogLoading loading = new DialogLoading(context)
* loading.show("123")
*
* @param msg 消息
*/
public AlertDialog show(String msg) {
alertDialog = new AlertDialog.Builder(mContext).create();
alertDialog.show();
Window window = alertDialog.getWindow();
window.setContentView(R.layout.dialog_loading);
window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
//window.setWindowAnimations(R.style.DialogAnimation);
window.setBackgroundDrawableResource(R.color.transparent);
window.setDimAmount(0f);//覆盖成透明度
this.msg = (TextView) window.findViewById(R.id.textView1);
this.msg.setText(msg);
//alertDialog.setCancelable(false);// 点击退出
return alertDialog;
}
示例5: init
import android.view.Window; //导入方法依赖的package包/类
private void init(Context context) {
contentLayout = new FrameLayout(context);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new android.app.Dialog(context);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);//位于屏幕底部
window.setWindowAnimations(R.style.Animation_Popup);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//android.util.AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
示例6: init
import android.view.Window; //导入方法依赖的package包/类
private void init(Context context) {
setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
setCancelable(false);//按返回键取消窗体
Window window = getWindow();
window.setWindowAnimations(ResHelper.getStyleRes(context, "BBS_AnimFadeInOut"));
//setup view
LinearLayout llItem = new LinearLayout(context);
int padding = ResHelper.dipToPx(context, 30);
llItem.setPadding(padding, padding, padding, padding);
llItem.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_bg_warning_dialog"));
llItem.setOrientation(LinearLayout.VERTICAL);
IOSLoadingView loadingView = new IOSLoadingView(context);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llp.gravity = Gravity.CENTER_HORIZONTAL;
llItem.addView(loadingView, llp);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(ResHelper.dipToPx(getContext(), 400), ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
window.setContentView(llItem, params);
}
示例7: initDialog
import android.view.Window; //导入方法依赖的package包/类
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
示例8: showLoadDialog
import android.view.Window; //导入方法依赖的package包/类
public static void showLoadDialog(Context context, String text) {
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.show();
Window window = alertDialog.getWindow();
window.setContentView(R.layout.dialog_loading);
ImageView iv = (ImageView) window.findViewById(R.id.dialog_iv);
TextView tv = (TextView) window.findViewById(R.id.dialog_tv);
tv.setText(text);
AnimationDrawable anim = (AnimationDrawable) iv.getBackground();
anim.start();
}
示例9: show
import android.view.Window; //导入方法依赖的package包/类
/**
* 显示消息提示框
*
* @param title
* @param msg
*/
public void show(String title, String msg) {
alertDialog = new AlertDialog.Builder(mContext).create();
alertDialog.setCancelable(true);
alertDialog.show();
Window window = alertDialog.getWindow();
window.setContentView(R.layout.dialog_msgbox);
window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
window.setBackgroundDrawableResource(R.color.transparent);
but_ok = (TextView) window.findViewById(R.id.but_ok);
but_cancel = (TextView) window.findViewById(R.id.but_cancel);
TextView tv_title = (TextView) window.findViewById(R.id.msgbox_title);
TextView tv_content = (TextView) window
.findViewById(R.id.msgbox_content);
tv_title.setText(title);
tv_content.setText(msg);
but_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
示例10: init
import android.view.Window; //导入方法依赖的package包/类
private void init(Context context) {
setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
setCancelable(true);//按返回键取消窗体
Window window = getWindow();
window.setWindowAnimations(ResHelper.getStyleRes(context, "BBS_AnimUpDown"));
//setup view
LinearLayout llItem = new LinearLayout(context);
int padding = ResHelper.dipToPx(context, 30);
llItem.setPadding(padding, padding, padding, padding);
llItem.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_bg_warning_dialog"));
llItem.setOrientation(LinearLayout.VERTICAL);
ImageView ivClose = new ImageView(context);
ivClose.setImageResource(ResHelper.getBitmapRes(context, "bbs_ic_warning_error"));
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llp.gravity = Gravity.CENTER_HORIZONTAL;
llItem.addView(ivClose, llp);
tvWarning = new TextView(context);
tvWarning.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResHelper.dipToPx(context, 12));
tvWarning.setTextColor(0xff3a4045);
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llp.gravity = Gravity.CENTER_HORIZONTAL;
llp.topMargin = ResHelper.dipToPx(context, 30);
llItem.addView(tvWarning, llp);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(ResHelper.dipToPx(getContext(), 400), ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
window.setContentView(llItem, params);
ivClose.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismiss();
}
});
}
示例11: onCreate
import android.view.Window; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clock);
Intent intent = getIntent();
// ��ȡ�������
String contentValue = intent.getStringExtra("content");
String alarmValue = intent.getStringExtra("alarmtime");
mp = MediaPlayer.create(ClockActivity.this, R.raw.alarm);// ����mediaplayer����
mp.start();// ��ʼ����
AlertDialog alertDialog = new AlertDialog.Builder(ClockActivity.this)
.create();
alertDialog.setCancelable(false); // ���öԻ�������ĵط��ͷ��ؼ�.
alertDialog.show();
Window window = alertDialog.getWindow();// �Զ���AlertDialog��ʽ
window.setContentView(R.layout.clock);
TextView tv_time = (TextView) window.findViewById(R.id.clocktime); // ��ʾʱ��
tv_time.setText(alarmValue);
TextView tv_message = (TextView) window.findViewById(R.id.clockcontent); // ��ʾ����
tv_message.setText(contentValue);
Button clockbutton = (Button) window.findViewById(R.id.btn_clock);// ȡ�����Ӱ�ť
clockbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mp.stop();
mp.reset();
ClockActivity.this.finish();
}
});
}
示例12: onCreate
import android.view.Window; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_clock);
Intent intent = getIntent();
// 获取相关数据
String contentValue = intent.getStringExtra("content");
String alarmValue = intent.getStringExtra("alarmtime");
mp = MediaPlayer.create(FestivalClockActivity.this, R.raw.alarm);// 创建mediaplayer对象
mp.start();
String Message = alarmValue + "\n" + contentValue; // 传入节日
AlertDialog alertDialog = new AlertDialog.Builder(
FestivalClockActivity.this).create();
alertDialog.setCancelable(false); // 禁用对话框以外的地方和返回键.
alertDialog.show();
Window window = alertDialog.getWindow();// 自定义AlertDialog样式
window.setContentView(R.layout.clock);
TextView tv_time = (TextView) window.findViewById(R.id.clocktime); // 显示时间
tv_time.setText(alarmValue);
TextView tv_message = (TextView) window.findViewById(R.id.clockcontent); // 显示内容
tv_message.setText(contentValue);
Button clockbutton = (Button) window.findViewById(R.id.btn_clock);// 取消闹钟按钮
clockbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mp.stop();
mp.reset();
FestivalClockActivity.this.finish();
}
});
}
示例13: setBottom
import android.view.Window; //导入方法依赖的package包/类
/**
* 让Dialog从底部出现/宽度全屏
*
* @param dialog
* @param rootView
*/
public static void setBottom(Dialog dialog, View rootView) {
Window window = dialog.getWindow();
// 在5.0以上手机必须加上这句代码
window.setBackgroundDrawableResource(android.R.color.transparent);
WindowManager.LayoutParams lp = window.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);
window.setGravity(Gravity.BOTTOM); //此处可以设置dialog显示的位置
window.setWindowAnimations(R.style.BottomDialogStyle); //添加动画
window.setContentView(rootView);//布局
}
示例14: beginCameraDialog
import android.view.Window; //导入方法依赖的package包/类
/**
* 开启选择拍照还是从相册取照片的对话框
*/
final void beginCameraDialog(){
DIALOG.show();
//获取window,方便设置属性
final Window window = DIALOG.getWindow();
if(window != null){
//设置dialog的自定义布局
window.setContentView(R.layout.dialog_camera_panel);
//设置dialog在底部
window.setGravity(Gravity.BOTTOM);
//设置动画
window.setWindowAnimations(R.style.anim_panel_up_from_bottom);
//设置透明背景
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//获取属性
final WindowManager.LayoutParams params = window.getAttributes();
//宽度
params.width = WindowManager.LayoutParams.MATCH_PARENT;
//弹出对话框背景为灰色
params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
params.dimAmount = 0.5f;
window.setAttributes(params);
//设置按钮点击事件
window.findViewById(R.id.btn_dialog_cancel).setOnClickListener(this);
window.findViewById(R.id.btn_dialog_take_photo).setOnClickListener(this);
window.findViewById(R.id.btn_dialog_pick_photo).setOnClickListener(this);
}
}
示例15: init
import android.view.Window; //导入方法依赖的package包/类
private void init(Context context) {
setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
setCancelable(true);//按返回键取消窗体
Window window = getWindow();
window.setWindowAnimations(ResHelper.getStyleRes(context, "BBS_AnimUpDown"));
//setup view
LinearLayout containLayout = new LinearLayout(context);
containLayout.setOrientation(LinearLayout.VERTICAL);
int leftPadding = ResHelper.dipToPx(context, 16);
containLayout.setPadding(leftPadding, 0, leftPadding, leftPadding / 2);
window.setContentView(containLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
if (listItems.size() > 0) {
LinearLayout itemContainer = new LinearLayout(context);
itemContainer.setOrientation(LinearLayout.VERTICAL);
itemContainer.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg"));
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
containLayout.addView(itemContainer, llp);
//添加item
int dividerHeight = context.getResources()
.getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_divider_height"));
int itemHeight = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_item_height"));
int txtSize = context.getResources().getDimensionPixelSize(ResHelper.getResId(context, "dimen", "bbs_chooser_dialog_txt_size"));
int txtColor = context.getResources().getColor(ResHelper.getColorRes(context, "bbs_chooser_dialog_txt_color"));
int length = listItems.size();
tvItems = new SparseArray<TextView>(length);
int topBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_top");
int middleBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_middle");
int bottomBgRes = ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg_bottom");
for (int i = 0; i < length; i++) {
int tag = i + 1;
TextView tvItem = new TextView(context);
tvItem.setTag(tag);
tvItem.setGravity(Gravity.CENTER);
tvItem.setTextColor(txtColor);
tvItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, txtSize);
tvItem.setText(listItems.get(i));
if (i == 0 && length > 1) {
tvItem.setBackgroundResource(topBgRes);
} else if (i == length - 1 && length > 1) {
tvItem.setBackgroundResource(bottomBgRes);
} else {
tvItem.setBackgroundResource(middleBgRes);
}
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight);
itemContainer.addView(tvItem, llp);
if (i < length - 1) {
View vLine1 = new View(context);
vLine1.setBackgroundColor(0xFFB7B7B7);
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dividerHeight);
itemContainer.addView(vLine1, llp);
}
tvItems.put(tag, tvItem);
}
TextView tvCancel = new TextView(context);
tvCancel.setTag(0);
tvCancel.setGravity(Gravity.CENTER);
tvCancel.setTextColor(context.getResources().getColor(ResHelper.getColorRes(context, "bbs_chooser_dialog_cancel_txt_color")));
tvCancel.setTextSize(TypedValue.COMPLEX_UNIT_PX, txtSize);
tvCancel.setText(ResHelper.getStringRes(context, "bbs_cancel"));
tvCancel.setBackgroundResource(ResHelper.getBitmapRes(context, "bbs_chooser_dialog_item_bg"));
llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, itemHeight);
llp.topMargin = ResHelper.dipToPx(context, 10);
containLayout.addView(tvCancel, llp);
tvItems.put(0, tvCancel);
}
}