android自定义吐司的使用
来源:互联网 发布:java 批量导入对象 编辑:程序博客网 时间:2024/04/29 15:59
先上效果图:
在这里注意,子控件的android:layout_centerInParent="true"属性使用时要注意,如果具体的子布局使用了这个属性,那么布局就会看着不协调。
public class CustomTusi extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
}
public void click(View view1){
Toast toast = new Toast(this);
View view = LayoutInflater.from(this).inflate(R.layout.toast_layout, null);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.setDuration(2000);
toast.show();
}
}
test.xml;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="click"
android:text="自定义吐司"
/>
</LinearLayout>
toast_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape_rec_little" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
>
<TextView
android:id="@+id/tv_toast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_centerHorizontal="true"
android:text="温馨提示"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_toast_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_toast"
android:layout_centerHorizontal="true"
android:padding="5dp"
android:text="自定义吐司成功" />
</RelativeLayout>
</RelativeLayout>
shape_rec_little.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#fff" />
<!-- android:radius 弧形的半径 -->
<corners android:radius="8dp" />
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:left="10dp"
android:right="10dp"
android:bottom="5dp"
android:top="5dp"
/>
<stroke
android:width="2px"
android:color="#ccc" />
</shape>
- android自定义吐司的使用
- android自定义吐司toast的方法
- Android自定义吐司(Toast)
- Android自定义吐司(Toast)
- 自定义好看的吐司
- Android 吐司 Toast 自定义 一行神奇的代码
- Android基础控件——Toast的自定义、按两次返回键返回桌面并弹出自定义吐司、仿映客吐司
- Android开发——Toast(吐司)的基本使用
- Android中吐司Toast、打印日志Log的使用
- 自定义吐司
- 自定义吐司
- 自定义吐司:
- 自定义吐司
- 自定义吐司
- 自定义吐司
- 自定义吐司
- 自定义吐司
- Android例子—自定义Toast(吐司)样式
- 为什么我认为数据结构与算法对前端开发很重要?
- yii2安装过程记录
- POJ1733 parity game(并查集)
- window实用快捷键
- 关于在Java中链接SQLServer数据库中失败的原因分析
- android自定义吐司的使用
- PING命令 原理
- 74-Search for a Range
- 救公主(BFS)
- MAC下安装多版本JDK和切换几种方式
- DOM解析
- Web爬虫:多线程、异步与动态代理初步
- 【NOIP2013模拟】开心小屋
- Android Drawable Resources系列3:<layer-list>