自定义dialog与事件回调
2016-01-27 23:25
148 查看
当我们自定义一个dialog的时候,点击里面的按钮时需要在当前的界面中处理相应的事件,这个时候我们就需要interface
首先我们写好自己的对话框布局:
在styles中写入dialog样式:
写一个接口类:
然后再调用dialog的地方和需要的地方实现就可以了:
首先我们写好自己的对话框布局:
<LinearLayout android:layout_width="300dp" android:layout_height="wrap_content" android:gravity="center_horizontal" android:background="#55000000" android:orientation="vertical" > <TextView android:id="@+id/txt_title" android:layout_width="fill_parent" android:layout_height="50dp" android:gravity="center" android:paddingTop="10dp" android:text="wwww" android:textColor="#000000" android:textSize="18sp" /> <TextView android:id="@+id/txt_hint" android:layout_width="fill_parent" android:layout_height="70dp" android:layout_marginTop="10dp" android:gravity="center_horizontal" android:text="kkkkkkk" android:textColor="#000000" android:textSize="18sp" /> <ImageView android:layout_width="fill_parent" android:layout_height="2dp" android:background="#BCBCBC" android:paddingLeft="10dp" android:paddingRight="10dp" /> <!--android:background="@drawable/button_corners_bg" --> <Button android:id="@+id/dialog_submit_orders_submit" android:layout_width="fill_parent" android:layout_height="60dp" android:background="@null" android:gravity="center" android:text="确认" android:textColor="@color/textchange_color" android:textSize="20sp" /> </LinearLayout>
在styles中写入dialog样式:
<style name="Dialog" parent="android:style/Theme.Dialog"> <item name="android:background">#00000000</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> </style>
写一个接口类:
public interface DialogTestInterface { public void testInterface(int code); }
然后再调用dialog的地方和需要的地方实现就可以了:
btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); testonet.testInterface(110); } });
@Override public void testInterface(int code) { if (code == 110){ Toast.makeText(MainActivity.this,"wkkkkk",Toast.LENGTH_SHORT).show(); }
相关文章推荐
- POJ 3020二分图的最大匹配
- 格式化数据#4:有关机器学习的SDK/Lib/API
- socket接口多线程数据传输
- C语言一些少见但很有用的语法
- POJ 3417 Network(dp+LCA)
- 安卓内存泄露
- NYOJ-13-Fibonacci数
- poj1679 The Unique MST
- centos 下vmware 下添加硬盘到root
- Day3~Day7(2016/1/23~2016/1/27)
- javaweb学习总结(四十一)——Apache的DBUtils框架学习
- 蚂蚁啃大象之zookeeper学习过程
- 玩转MySQL之Linux下的简单操作(服务启动与关闭、启动与关闭、查看版本)
- hdu1754 区间查询+点修改 分块模板
- Android自定义属性格式
- oracle with as介绍
- 以Attention Model为例谈谈两种研究创新模式
- spring mvc 的jpa JpaRepository数据层 访问方式汇总
- spring AOP
- 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-06-激活函数