Android xml布局之dialog
来源:互联网 发布:淘宝店招怎么做 编辑:程序博客网 时间:2024/06/16 15:21
使用环境:
需要dialog的时候
使用方法:
1 样式:
<color name="transparent">#00000000</color>
<style name="TaoDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item><!--边框--> <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上--> <item name="android:windowIsTranslucent">false</item><!--半透明--> <item name="android:windowNoTitle">true</item><!--无标题--> <item name="android:windowBackground">@color/transparent</item><!--背景透明--> <item name="android:backgroundDimEnabled">true</item><!--模糊--></style>
public class BaseDialog extends Dialog implements Observable { private transient PropertyChangeRegistry mCallbacks; @Override public void addOnPropertyChangedCallback(OnPropertyChangedCallback callback) { synchronized (this) { if (mCallbacks == null) { mCallbacks = new PropertyChangeRegistry(); } } mCallbacks.add(callback); } @Override public void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback) { synchronized (this) { if (mCallbacks == null) { return; } } mCallbacks.remove(callback); } public void notifyPropertyChanged(int fieldId) { synchronized (this) { if (mCallbacks == null) { return; } } mCallbacks.notifyCallbacks(this, fieldId, null); } private BaseActivity activity; private float alpha = 1; private Object tag; public void setTag(Object tag) { this.tag = tag; } public Object getTag() { return tag; } public void setShowingAlpha(float alpha) { this.alpha = alpha; } public BaseDialog(Context context) {// super(context, R.style.Translucent_Dialog); super(context, R.style.TaoDialog); if (context instanceof BaseActivity) this.activity = (BaseActivity) context; requestWindowFeature(Window.FEATURE_NO_TITLE); setCancelable(true); WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; getWindow().setAttributes(layoutParams); } public Context getActivity() { if (activity != null) return activity; else return super.getContext(); } @Override public void show() { handler.removeMessages(0); handler.sendEmptyMessage(1); } public void showDelayed(long time) { if (time == -1) handler.sendEmptyMessageDelayed(0, 10 * 1000); else handler.sendEmptyMessageDelayed(0, time); this.show(); } @Override public void dismiss() { handler.removeMessages(0); handler.sendEmptyMessage(2); } private Handler handler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: if (!isShowing()) return; dismiss(); break; case 1: if (isShowing()) return; BaseDialog.super.show(); if (activity != null) { if (activity.isFinishing()) return; if (alpha != 1) { WindowManager.LayoutParams params = activity.getWindow().getAttributes(); params.alpha = alpha; activity.getWindow().setAttributes(params); } } break; case 2: if (!isShowing()) return; BaseDialog.super.dismiss(); if (activity == null || activity.isFinishing()) return; if (alpha != 1) { WindowManager.LayoutParams params = activity.getWindow().getAttributes(); params.alpha = 1f; activity.getWindow().setAttributes(params); } break; } } };}
2 一个简单的布局:
<?xml version="1.0" encoding="utf-8"?><layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="delete" type="com.yarui.app.client.ui.view.dialog.DeleteDialog"/> </data> <LinearLayout android:orientation="vertical" android:background="@drawable/mainbackground" android:layout_width="@dimen/threehundred" android:layout_height="@dimen/oneHundredninety"> <TextView android:layout_width="match_parent" android:layout_height="@dimen/sixty" android:gravity="center" android:text="@string/lookimage" android:textSize="@dimen/textSizeA" android:textColor="@color/text_block" android:onClick="@{delete.lookPoint}" /> <include layout="@layout/one"/> <TextView android:layout_width="match_parent" android:layout_height="@dimen/sixty" android:gravity="center" android:text="@string/deletePhoto" android:textSize="@dimen/textSizeA" android:textColor="@color/text_block" android:onClick="@{delete.deletePoint}" /> <include layout="@layout/henglineten"/> <TextView android:onClick="@{delete.cancelPoint}" android:layout_width="match_parent" android:layout_height="@dimen/sixty" android:gravity="center" android:text="@string/cancel" android:textSize="@dimen/textSizeA" android:textColor="@color/text_block" /> </LinearLayout></layout>
draw able:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/FFFFFF"/> <corners android:radius="@dimen/twenty"/> <stroke android:color="@color/FFFFFF" android:width="@dimen/one"/></shape>
public class DeleteDialog extends BaseDialog { private Context mcontext; private DialogDeletephotoBinding deletephotoBinding; private onCheckItemClick onCheckItemClick; public DeleteDialog(Context context) { super(context); this.mcontext = context; deletephotoBinding = DataBindingUtil.inflate(LayoutInflater.from(mcontext), R.layout.dialog_deletephoto,null,false); deletephotoBinding.setDelete(this); setContentView(deletephotoBinding.getRoot()); } public void setOnCheckItemClick(onCheckItemClick onCheckItemClick) { this.onCheckItemClick = onCheckItemClick; } public void lookPoint(View view) { if (onCheckItemClick != null) { onCheckItemClick.onConfirmClick(); } dismiss(); } public void deletePoint(View view) { if (onCheckItemClick != null) { onCheckItemClick.onCancelClick(); } dismiss(); } public void cancelPoint(View view){ if (onCheckItemClick != null) { onCheckItemClick.onCloseClick(); } dismiss(); }}
在activity中使用
DeleteDialog deleteDialog = new DeleteDialog(LoginActivity.this);deleteDialog.show();
本文中使用了初级的databinding,
自定义的接口:
public interface onCheckItemClick { void onCancelClick(); void onConfirmClick(); void onCloseClick();}
思路不清晰……作为笔记使用。
重点 1 显示模糊背景的style
2 dialog的base代码
3 dialog的用法
阅读全文
0 0
- Android xml布局之dialog
- Android之.XML布局
- Android 之 XML 布局
- android alertdialog布局 dialog布局
- android alertdialog布局 dialog布局
- android Dialog 布局疑惑
- 【android控件】dialog自定义布局
- Android自定义dialog的布局
- Android dialog 对话框自定义布局
- Android自定义dialog弹出布局
- Android自定义dialog弹出布局
- Android自定义dialog弹出布局
- android Dialog 自定义 实现xml
- android xml dialog的使用
- 关于Android中xml布局文件之android 入门xml布局文件
- 关于Android中xml布局文件之android 入门xml布局文件
- Android布局xml布局文件
- android之Dialog
- Python2 socket示例
- Python 从入门到实践 5-3 课后习题
- Java中使用Jedis操作Redis
- 马云在2017乌镇互联网大会讲了这三个观点
- 没有dev-server.js文件该怎么配置本地数据
- Android xml布局之dialog
- quartz调度
- 步进电机工作原理
- Android热修复框架学习及应用
- centOS 7 下防火墙firewalld添加和开发端口
- /opt目录和/usr目录的区别
- C++构造函数
- Python机器学习初识
- xcode使用dlib库