为了账号安全,请及时绑定邮箱和手机立即绑定

安卓中的对话框自定义(Popuwindow,Dialog,Toast)自定义

标签:
Android

自定义Toast

分两步:(1)设置位置

(2)设置view

代码:

Toast toast = Toast.makeText(NewsDetaileActivity.this, "收藏成功1",Toast.LENGTH_LONG);

//设置位置

toast.setGravity(Gravity.CENTER, 0, 0);

//设置外观内容

View view  =

LayoutInflater.from(NewsDetaileActivity.this).inflate(R.layout.my_toast, null);

((TextView)view.findViewById(R.id.toast_mess)).setText(txt);

toast.setView(view);

toast.show();

Dialog

《1》普通设置Diog;

dialog = new AlertDialog.Builder(this).setTitle("请选择字体大小").

 setSingleChoiceItems(R.array.comment_size_list, 0, new DialogInterface.OnClickListener() {


@Override

public void onClick(DialogInterface arg0, int arg1) {

// TODO Auto-generated method stub

//Toast.makeText(SettingActivity.this, getResources().getStringArray(R.array.comment_size_list)[arg1], Toast.LENGTH_LONG).show();

set_comment = (TextView)findViewById(R.id.set_comment);

set_comment.setText(getResources().getStringArray(R.array.comment_size_list)[arg1]);

dialog.dismiss();

}

}).setNegativeButton("取消", new DialogInterface.OnClickListener() {


@Override

public void onClick(DialogInterface arg0, int arg1) {

// TODO Auto-generated method stub

dialog.dismiss();

}

}).create();

 dialog.show();

《2》自定义dialog

private void exitDialog(){

if (exitDialog==null){

exitDialog = new AlertDialog.Builder(this).create();

exitDialog.show();

exitDialog.getWindow().

setContentView(R.layout.exit_dialog);

exitDialog.getWindow().findViewById(R.id.bt_OK).setOnClickListener(new OnClickListener() {


@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

exitDialog.dismiss();

HomeActivity.this.finish();

}

});


自定义Popuwindow

《1》建立

View view  = LayoutInflater.from(this).inflate(R.layout.popup_window_demo, null);


//新建popuwindow

popuwindow = new PopupWindow(view,

ViewGroup.LayoutParams.MATCH_PARENT,

ViewGroup.LayoutParams.WRAP_CONTENT);

//设置获得焦点,不加不能实现点击外侧区域关闭功能。

popuwindow.setFocusable(true);

popuwindow.setOutsideTouchable(true);

ColorDrawable drawable = new ColorDrawable();

popuwindow.setBackgroundDrawable(drawable);


//加动画

//popuwindow.setAnimationStyle(TRIM_MEMORY_COMPLETE);

}

 

--2--show~~用的时候


makePopuwindow();

int[] location =new int[2];

newsDetaliLayout.getLocationOnScreen(location);

popuwindow.showAtLocation(newsDetaliLayout, Gravity.NO_GRAVITY,location[0], location[1]-popuwindow.getHeight());

原文链接:http://www.apkbus.com/blog-476203-59086.html

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消