Android开发中的三种提示(Dialog,Toast,Snackbar)实现
来源:互联网 发布:nba2k14中文版下载软件 编辑:程序博客网 时间:2024/06/10 06:29
1.Xml布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/tv_dialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="DIALOG" android:background="@color/green" android:gravity="center" android:textSize="20sp"/> <TextView android:id="@+id/tv_toast" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="TOAST" android:background="@color/green" android:gravity="center" android:textSize="20sp"/> <TextView android:id="@+id/tv_snackbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="SNACKBAR" android:background="@color/green" android:gravity="center" android:textSize="20sp"/> </LinearLayout>
2.引入Snackbar框架
在项目文件下的build.gradle文件里加上
dependencies { /**snackbar引入框架*/ compile 'com.android.support:design:25.+'
3.在MainActivity中的实现
public class MainActivity extends AppCompatActivity implements View.OnClickListener { TextView tvDialog; TextView tvToast; TextView tvSnackbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvDialog = (TextView) findViewById(R.id.tv_dialog); tvToast = (TextView) findViewById(R.id.tv_toast); tvSnackbar = (TextView) findViewById(R.id.tv_snackbar); tvDialog.setOnClickListener(this); tvToast.setOnClickListener(this); tvSnackbar.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { /**实现弹出dialog*/ case R.id.tv_dialog: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("提示"); builder.setMessage("这是一则提示消息!"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); break; /**实现弹出toast*/ case R.id.tv_toast: Toast.makeText(this,"我是一则toast提示消息",Toast.LENGTH_SHORT).show(); break; /**实现弹出snackbar*/ case R.id.tv_snackbar: Snackbar.make(v,"我是一则提示消息消息",Snackbar.LENGTH_SHORT).setAction("确定", new View.OnClickListener() { @Override public void onClick(View v) { } }).show(); break; } }}
好了,以上就三种提示的实现方式,比较简单,当然如果有什么不理解的可以加我qq:1029063917,欢迎沟通交流技术问题。
阅读全文
0 0
- Android开发中的三种提示(Dialog,Toast,Snackbar)实现
- Android 信息提示Dialog、Toast和Snackbar
- Android提醒:Dialog,Toast,Snackbar
- Android dialog,toast,snackbar小节
- Android开发之————Toast、Dialog、SnackBar
- Snackbar提示,Toast和Dialog之间
- Android开发笔记:类似Toast的提示控件:SnackBar
- Android弹框使用:Dialog&Toast&Snackbar
- Android Dialog、Toast和Snackbar详解
- Android提醒技巧,Dialog、Toast和Snackbar
- Android提醒,Dialog、Toast和Snackbar。
- Android中Dialog、Snackbar、Toast使用区别?
- Android开发笔记(一百二十七)活用提示窗Toast和Snackbar
- Android 活用提示窗Toast和Snackbar
- Android开发——你真的了解Dialog、Toast和Snackbar吗
- android中的提示类组件toast,dialog,notification,widget
- Android中Dialog、Toast和Snackbar使用场景以及技巧
- Android提醒微技巧Dialog、Toast和Snackbar
- 键盘事件
- 整数排序
- pandas.DataFrame.fillna 的几种method
- 网路协议
- Ignatius and the Princess IV
- Android开发中的三种提示(Dialog,Toast,Snackbar)实现
- Java并发编程:Thread类的使用
- 在主方法中创建String型变量,实现字符变量的大小写转换,并将转换后的结果输出
- 右键菜单事件
- [笔记]: 树链剖分
- IO流的一些知识点
- uva10474
- 0.masm32-搭建环境和MessageBoxA弹框
- python 入门