自定义toast的使用
来源:互联网 发布:杭州软件测试在职培训 编辑:程序博客网 时间:2024/06/05 01:13
写一个布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/toast_view_bg"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户提示" />
</LinearLayout>
布局的布局写一个shape文件:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="false" >
<solid android:color="#880000ff" />
<corners android:radius="5dp"/>
<size
android:height="50dp"
android:width="50dp" />
</shape>
代码逻辑的实现:
写一个BaseActivity或者在BaseFragment写一个关于弹出toast的方法
public class BaseAbtivity extends Activity {
private TextView tv;
private View view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void showToast(String msg) {
Toast toast = new Toast(this);
view = View.inflate(this, R.layout.toast_view, null);
tv = (TextView) view.findViewById(R.id.tv);
tv.setText(msg);
toast.setView(view);
toast.show();
}
}
如果需要toast显示更加多样就自己修改布局就可以实现了。
- 自定义toast的使用
- 自定义toast的使用
- 使用自定义的Toast
- Android自定义Toast的使用
- Android Toast自定义使用
- Android Toast自定义使用
- Android Toast自定义使用
- Android自定义Toast,指定Toast信息显示的位置并使用Toast显示其他View
- 自定义显示的Toast
- 自定义Toast的创建
- 自定义toast的风格。
- Toast的自定义用法
- 自定义Toast的实现
- Android:自定义的Toast
- 自定义Toast的实现
- 简单的自定义Toast
- 自定义toast的布局
- Toast的自定义
- 【java】Cookie实现简单浏览商品
- 使用Visual Leak Detector for Visual C++ 捕捉内存泄露
- 聚铭网络喊话:什么是真正的网络安全管理?
- 搭建流媒体服务器
- Android对话框定时自动关闭的实现
- 自定义toast的使用
- JAVA常用代码。干货来啦!
- bootstrap 网页中代码显示<code><pre>用法
- 《java并发编程实战》第11章-性能与可伸缩性
- [leetcode] 144. Binary Tree Preorder Traversal
- jsp EL表达式 方法详解
- 【C#】XML的创建与读取
- fwrite和fread函数的用法小结
- 上传简历的上传代码