自定义Dialog
来源:互联网 发布:下载漫画的软件 编辑:程序博客网 时间:2024/05/23 10:25
之前一直没有写东西的习惯,而后也是听取了同事们的建议,简简单单的写点东西,只希望自己再次用到的时候能够减少点时间:
(一直在想将view封装到dialog里面好,还是将view分离出来合理)
首先Dialog的样式
<style name="MyDialog" parent="android:style/Theme.Dialog"> <!--背景颜色和透明度--> <item name="android:windowBackground">@android:color/transparent</item> <!--是否去除标题 --> <item name="android:windowNoTitle">true</item> <!--是否去除边框--> <item name="android:windowFrame">@null</item> <!--是否浮现在activity之上--> <item name="android:windowIsFloating">true</item> <!--是否模糊--> <item name="android:backgroundDimEnabled">false</item></style>Dialog的布局只是简单的写了一下,根据自己的需求写所需要的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/no" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/yes" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout></LinearLayout>Dialog
public class MyDialog extends Dialog { private View mLayoutView; private onNoClickListener noClickListener;//取消按钮被点击了的监听器 private onYesClickListener yesClickListener;//确定按钮被点击了的监听器 private Button yes,no;//确定与取消按钮 public void setNoClickListener(onNoClickListener noClickListener) { this.noClickListener = noClickListener; } public void setYesClickListener(onYesClickListener yesClickListener) { this.yesClickListener = yesClickListener; } public MyDialog(Context context ,int styleId,View layoutView) { super(context,styleId); mLayoutView=layoutView; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(mLayoutView); setCanceledOnTouchOutside(false); initView(); } /** *初始化控件 */ private void initView() { yes= (Button) mLayoutView.findViewById(R.id.yes); no= (Button) mLayoutView.findViewById(R.id.no); //点击事件 yes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { yesClickListener.onYesClick(); } }); no.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { noClickListener.onNoClick(); } }); } /** * 取消按钮接口 */ public interface onNoClickListener{ public void onNoClick(); } /** * 确定按钮接口 */ public interface onYesClickListener{ public void onYesClick(); }}activity中的内容
private TextView textView;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView= (TextView) findViewById(R.id.tv); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View view= LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog,null); MyDialog myDialog=new MyDialog(MainActivity.this,R.style.MyDialog,view); myDialog.setYesClickListener(new MyDialog.onYesClickListener() { @Override public void onYesClick() { Toast.makeText(MainActivity.this,"click yes",Toast.LENGTH_SHORT).show(); } }); myDialog.show(); } });}
阅读全文
0 0
- 自定义Dialog---继承Dialog
- 自定义Dialog android Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义dialog
- 自定义 Dialog
- 自定义dialog
- 自定义 dialog
- 自定义Dialog
- 自定义 Dialog
- 自定义Dialog
- 自定义dialog
- 自定义Dialog
- 自定义 Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义Dialog
- 自定义Dialog
- python之路——函数式编程
- jquery.printArea改进
- 人工智能+
- zookeeper学习点
- c++ winpcap开发(5)
- 自定义Dialog
- MySQL事务的可串行化
- 一分钟了解“matlab把一个矩阵矩阵范围拉伸到minVal~maxVal的范围内”
- TensorFlow 之命令行参数
- SHUOJ几队周尼玛
- 日常问题总结 一
- Performance Comparison of H.265_MPEG-HEVC, VP9, and H.264/MPEG-AVC Encoders
- 第5章 神经网络
- 初学如何选择thread数量