自定义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());
共同学习,写下你的评论
评论加载中...
作者其他优质文章